0

我定义了一个类名 TextColumns.cs,它有一个 DependencyProperty RichTextBlockContentProperty:

public static readonly DependencyProperty RichTextBlockContentProperty =
    DependencyProperty.Register("RichTextBlockContent", typeof(string),
typeof(RichTextColumns), new PropertyMetadata(""));

public string RichTextBlockContent
{
    get { return (string)GetValue(RichTextBlockContentProperty); }
    set  //Debug, but the SetValue won't fire
    {
        SetValue(RichTextBlockContentProperty, value);
    }
} 

在 XAML 中,我将其用作

<FlipView x:Name="flipView"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}">
            <FlipView.ItemTemplate>
                <DataTemplate  x:Name="myDataTemplate">
                    <UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
                        <ScrollViewer x:Name="scrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" Grid.Row="1">
                            <!-- Content is allowed to flow across as many columns as needed -->
                            <common:RichTextColumns x:Name="richTextColumns" Margin="117,0,117,47"
                                                    RichTextBlockContent="{Binding title}">

                                <RichTextBlock x:Name="richTextBlock" Width="560" Style="{StaticResource ItemRichTextStyle}">
                                    <Paragraph>
                                        <Run x:Name="RunText" FontSize="26" FontWeight="SemiBold" Text="{Binding title}"/>
                                    </Paragraph>
                                </RichTextBlock>
                </common:RichTextColumns>
            </UserControl>
        </DataTemplate> 
    </FlipView.ItemTemplate>
</FlipView>

当页面加载时,假设 RichTextBlockContent 将获取 Binding“标题”的值,而 RichTextBlock 中的 Binding 工作。

有什么我错过的吗?

4

1 回答 1

1

setter 不会被调用。如果您需要在设置值时执行逻辑,则需要在 PropertyMetadata 构造函数中提供 PropertyChanged 回调

http://msdn.microsoft.com/en-us/library/ms557330.aspx

于 2012-08-31T04:21:47.503 回答