为什么绑定适用于个人TextBlock
但不适用于TextBlock
内的Button.Flyout
。
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RichTextBlock Name="rtbMain" attc:RichTextBlockAttached.CurrentFlyoutText="Trial Attached Binding" RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True">
<Paragraph>
Button Flyout should display Trial Attached Binding
</Paragraph>
</RichTextBlock>
<Button x:Name="btt" RelativePanel.Below="rtbMain" RelativePanel.AlignHorizontalCenterWith="rtbMain" Content="Click to test binding">
<Button.Flyout>
<Flyout>
<Grid>
<TextBlock Text="{Binding Path=(attc:RichTextBlockAttached.CurrentFlyoutText), ElementName=rtbMain, Mode=TwoWay}"/>
</Grid>
</Flyout>
</Button.Flyout>
</Button>
<TextBlock RelativePanel.Below="btt" RelativePanel.AlignHorizontalCenterWith="btt" Text="{Binding Path=(attc:RichTextBlockAttached.CurrentFlyoutText), ElementName=rtbMain, Mode=TwoWay}"/>
</RelativePanel>
和附加属性定义:
public static class RichTextBlockAttached
{
public static readonly DependencyProperty CurrentFlyoutTextProperty =
DependencyProperty.RegisterAttached(
"CurrentFlyoutText",
typeof(string),
typeof(RichTextBlockAttached),
new PropertyMetadata("", OnCurrentFlyoutTextChanged));
private static void OnCurrentFlyoutTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//throw new NotImplementedException();
}
public static string GetCurrentFlyoutText(DependencyObject obj)
{
return (string)obj.GetValue(CurrentFlyoutTextProperty);
}
public static void SetCurrentFlyoutText(DependencyObject obj, string value)
{
obj.SetValue(CurrentFlyoutTextProperty, value);
}