将依赖属性设置为XAML Element时遇到问题。 XAML:
<local2:RichTextColumns xmlns:local2="using:App2.Common">
<local2:RichTextColumns.ColumnTemplate>
<DataTemplate x:Name="overflowControl1">
<RichTextBlockOverflow Width="1000" Margin="5,0,0,0"/>
</DataTemplate>
</local2:RichTextColumns.ColumnTemplate>
<RichTextBlock Foreground="Black" Width="1000">
<Paragraph>
</Paragraph>
</RichTextBlock>
</local2:RichTextColumns>
C#
var tmp = (DataTemplate)FindName("overflowControl1");
tmp.SetValue(RichTextBlockOverflow.ActualWidthProperty, 100);
导致
灾难性故障(HRESULT异常:0x8000FFFF(E_UNEXPECTED))。
我也尝试过使用RichTextBlockOverflow.WidthProperty
提前谢谢你:)
答案 0 :(得分:1)
尝试
<local2:RichTextColumns xmlns:local2="using:App2.Common">
<local2:RichTextColumns.ColumnTemplate>
<DataTemplate>
<RichTextBlockOverflow x:Name="overflowControl1" Width="1000" Margin="5,0,0,0"/>
</DataTemplate>
</local2:RichTextColumns.ColumnTemplate>
<RichTextBlock Foreground="Black" Width="1000">
<Paragraph>
</Paragraph>
</RichTextBlock>
</local2:RichTextColumns>
C#
var tmp = (RichTextBlockOverflow)FindName("overflowControl1");
tmp.SetValue(RichTextBlockOverflow.WidthProperty, 100);
答案 1 :(得分:0)
好的找到了很好的解决方案。我使用绑定将相同的宽度设置为RichTextBlock和RichTextBlockOverflow。