- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在 xaml 中显示一些文本,但看起来它在中间被截断了,但下一个词出现了。这是我的 xaml。
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115" />
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" FontFamily="Arial" FontSize="13.33333333">ABCDE IAATA Corp.</TextBlock>
</Grid>
Which results in this .请注意中间词 (IAATA) 丢失了,但最后一个词 (Corp.) 在那里。知道这里发生了什么吗?我希望第三个词会换行,或者第二个词会出现,最后一个词被截断,甚至第二个和第三个词都被截断,但不是这个。
我能够在 VS 和 Kaxaml 中对此进行测试
更新对于更多上下文,进入的 xaml 是从其他地方生成的。稍后我对 xaml 元素进行了一些测量,这会引发“FatalExecutionEngineError”异常,该异常会立即终止应用程序。
消息是
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in
'C:\Projects\TestFailFast\TestFailFast\bin\Debug\TestFailFast.vshost.exe'.
Additional information: The runtime has encountered a fatal error. The address of the error was at 0x583ee28b, on thread 0x2af0. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack
并且通过事件查看器日志获得的堆栈跟踪是
Application: Services.BackEnd.exe Framework Version: v4.0.30319 Description: The application requested process termination through System.Environment.FailFast(string message). Message: Unrecoverable system error. Stack: at System.Environment.FailFast(System.String) at System.Windows.Controls.TextBlock.IsAtCaretUnitBoundary(System.Windows.Documents.ITextPointer, Int32, Int32) at System.Windows.Documents.TextContainer.IsAtCaretUnitBoundary(System.Windows.Documents.TextPointer) at System.Windows.Documents.TextPointer.System.Windows.Documents.ITextPointer.get_IsAtCaretUnitBoundary() at System.Windows.Documents.TextPointerBase.IsAtCaretUnitBoundary(System.Windows.Documents.ITextPointer) at System.Windows.Documents.TextPointerBase.MoveToNextInsertionPosition(System.Windows.Documents.ITextPointer, System.Windows.Documents.LogicalDirection) at System.Windows.Documents.TextPointer.System.Windows.Documents.ITextPointer.GetNextInsertionPosition(System.Windows.Documents.LogicalDirection) ...
This is only exposed if I have the above xaml wrapped in a FixedDocument like
<FixedDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<PageContent>
<FixedPage>
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115" />
</Grid.ColumnDefinitions>
<TextBlock Text="ABCDE IAATA Corp." FontFamily="Arial" FontSize="13.333333" TextWrapping="Wrap" HorizontalAlignment="Center"/>
</Grid>
</FixedPage>
</PageContent>
</FixedDocument>
我这里有一个样本复制器
class Program {
[STAThread]
static void Main(string[] args) {
var fixedPageXaml = @"<FixedDocument xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<PageContent>
<FixedPage>
<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""115"" />
</Grid.ColumnDefinitions>
<TextBlock Text=""ABCDE IAATA Corp."" FontFamily=""Arial"" FontSize=""13.333333"" TextWrapping=""Wrap"" HorizontalAlignment=""Center""/>
</Grid>
</FixedPage>
</PageContent>
</FixedDocument>";
//Search through all xaml elements untill the TextBlock is found
var textBlock = FindTextBlock(XamlReader.Parse(fixedPageXaml));
var inline = textBlock.Inlines.FirstInline;
//Get a TextPointer to the end of a line that is specified relative to the current text pointer
// Add 1 to get the beginning of the line following the one count is requesting
var nextLineStart = inline.ElementStart.GetLineStartPosition(0 + 1);
if (nextLineStart != null) {
//Get the insertion position at the end of the document
//CRASH!
var nextPos = nextLineStart.GetNextInsertionPosition(LogicalDirection.Backward);
}
Console.WriteLine("Done");
Console.Read();
}
private static TextBlock FindTextBlock(object root) {
var fe = root;
while (fe.GetType() != typeof(TextBlock)) {
if (fe is FixedDocument) {
foreach (var p in ((FixedDocument)fe).Pages) {
var ret = FindTextBlock(p);
if (ret != null) {
return ret;
}
}
} else if (fe is FixedPage) {
foreach (UIElement c in ((FixedPage)fe).Children) {
var ret = FindTextBlock(c);
if (ret != null) {
return ret;
}
}
} else if (fe is PageContent) {
fe = ((PageContent)fe).Child;
} else if (fe is Grid) {
foreach (UIElement c in ((Grid)fe).Children) {
var ret = FindTextBlock(c);
if (ret != null) {
return ret;
}
}
}
}
if (fe.GetType() == typeof(TextBlock)) {
return fe as TextBlock;
} else {
return null;
}
}
}
这已在 .net 版本 4.6.2 中测试
最佳答案
如果您希望您的文本 block 与父文本 block 具有相同的宽度,请不要将 HorizontalAlignment 设置为 Left。作为网格子项,它将默认为 Stretch,这正是您想要的。如果需要,在 TextBlock 上设置 TextAlignment 以对齐文本。
我想知道这对于换行算法中的算法来说是否不是一个有趣的极端情况,其中“丢失”的文本只是放在看不见的地方:如果我将 FontSize 调低到 13.256(但不是 13.257),它换行适本地。如果我拨到 13.341(但不是 13.3405),它会正确换行。
关于c# - Xaml TextBlock 中的中间词丢失,但最后一个词不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46938827/
这个问题在这里已经有了答案: “return” and “try-catch-finally” block evaluation in scala (2 个回答) 7年前关闭。 为什么method1返
我有一个动态列表,需要选择最后一项之前的项目。 drag your favorites here var lastLiId = $(".album
我想为每个线程执行特定操作,因此,我认为tearDown Thread Group 不起作用。 是否有任何替代方法可以仅在线程的最后一次迭代时运行“仅一次 Controller ”? 谢谢。 最佳答案
在我的书中它使用了这样的东西: for($ARGV[0]) { Expression && do { print "..."; last; }; ... } for 循环不完整吗?另外,do 的意义何
我想为每个线程执行特定操作,因此,我认为tearDown Thread Group 不起作用。 是否有任何替代方法可以仅在线程的最后一次迭代时运行“仅一次 Controller ”? 谢谢。 最佳答案
有没有可能 finally 不会被调用但应用程序仍在运行? 我在那里释放信号量 finally { _semParallelUpdates.Re
我收藏了 对齐的元素,以便它们形成两列。使用 nth-last-child 的组合和 nth-child(even) - 或任何其他选择器 - 是否可以将样式应用于以下两者之一:a)最后两个(假设
我正在阅读 Jon Skeet 的 C# in Depth . 在第 156 页,他有一个示例, list 5.13“使用多个委托(delegate)捕获多个变量实例化”。 List list = n
我在 AM4:AM1000 范围内有一个数据列表(从上到下有间隙),它总是被添加到其中,我想在其中查找和总结最后 4 个结果。但我只想找到与单独列相对应的结果,范围 AL4:AL1000 等于单元格
我最近编写了一个运行良好的 PowerShell 脚本 - 然而,我现在想升级该脚本并添加一些错误检查/处理 - 但我似乎被第一个障碍难住了。为什么下面的代码不起作用? try { Remove-
这个问题在这里已经有了答案: Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of
使用 Django 中这样的模型,如何检索 30 天的条目并计算当天添加的条目数。 class Entry(models.Model): ... entered = models.Da
我有以下代码。 public static void main(String[] args) { // TODO Auto-generated method stub
这个问题在这里已经有了答案: Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of
这个问题已经有答案了: Multiple returns: Which one sets the final return value? (7 个回答) 已关闭 8 年前。 我正在经历几个在工作面试中
$ cat n2.txt apn,date 3704-156,11/04/2019 3704-156,11/22/2019 5515-004,10/23/2019 3732-231,10/07/201
我可以在 C/C++ 中设置/禁用普通数组最后几个元素的读(或写)访问权限吗?由于我无法使用其他进程的内存,我怀疑这是可能的,但如何实现呢?我用谷歌搜索但找不到。 如果可以,怎样做? 因为我想尝试这样
我想使用在这里找到的虚拟键盘组件 http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx就像 Windows 中的屏幕键盘 (O
我正在运行一个 while 循环来获取每个对话的最新消息,但是我收到了错误 [18-Feb-2012 21:14:59] PHP Warning: mysql_fetch_array(): supp
这个问题在这里已经有了答案: How to get the last day of the month? (44 个答案) 关闭 8 年前。 这是我在这里的第一篇文章,所以如果我做错了请告诉我...
我是一名优秀的程序员,十分优秀!