Silverlight 具有从属属性的绑定

Silverlight 具有从属属性的绑定,silverlight,binding,windows-8,microsoft-metro,dependency-properties,Silverlight,Binding,Windows 8,Microsoft Metro,Dependency Properties,我定义了一个类名TextColumns.cs,它具有DependencyProperty RichTextBlockContentProperty: public static readonly DependencyProperty RichTextBlockContentProperty = DependencyProperty.Register("RichTextBlockContent", typeof(string), typeof(RichTextColumns), new P

我定义了一个类名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将获得绑定“title”的值,而RichTextBlock中的绑定起作用


我错过了什么吗

二传手不会被呼叫。如果需要在设置值时执行逻辑,则需要在PropertyMetadata构造函数中提供PropertyChanged回调


您不使用
关闭
滚动查看器