0
votes

I have got problem while setting dependency property to 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);

It results in

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).

I have also tried using RichTextBlockOverflow.WidthProperty

Thank you in advance :)

2
The ActualWidth property is not meant to be set, it's read-only - Thomas Levesque
maybe you should give x:Name="overflowControl1" to the RichTextBlockOverflow not to the DataTemplate - S3ddi9
It looks like tmp is null ??? but when findname can't find element it should throw an exception (apart from fact that this name exists) - Krzysztof Kaczor

2 Answers

1
votes

try

<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);
0
votes

Ok Found great solution. I used binding to set same width to RichTextBlock and RichTextBlockOverflow.