如何绑定到 ContentControl.Content 的附件 属性
How to bind to ContentControl.Content's attached property
我有一个模块化的 WPF 应用程序 - Shell、模块 1、模块 2、模块 3。
每个模块都有这样定义的视图:
<UserControl>
<TextBox x:Name="DefaultControl"/>
<UserControl.Tag>
<Binding ElementName="DefaultControl"/>
</UserControl.Tag>
</UserControl>
Shell 有 MainView,它使用 WPFToolkit BusyIndicator 控件。 MainView 是这样定义的:
<Window>
<xctk:BusyIndicator IsBusy="{Binding ElementName=MainRegion, Path=Content.DataContext.IsBusy}"
FocusAfterBusy="{Binding Path=Content.Tag, ElementName=MainRegion}">
<ContentControl x:Name="MainRegion">
</ContentControl>
</xctk:BusyIndicator>
</Window>
BusyIndicator.FocusAfterBusy 用于在 IsBusy 变为 False 时将焦点设置在任何名为 DefaultControl 的视图元素上。
使用 Tag 属性 绑定时效果很好。
但是现在我想为此使用一个名为 DefaultControl (object) 的简单附加 属性。
视图变为:
<UserControl>
<TextBox x:Name="DefaultControl"/>
<ext:FocusExtension.DefaultControl>
<Binding ElementName="DefaultControl"/>
</ext:FocusExtension.DefaultControl>
</UserControl>
我应该如何更改 BusyIndicator.FocusAfterBusy="{Binding Path=Content.Tag, ElementName=MainRegion}" 中的路径以绑定到 MainRegion.Content 的附件 属性(默认控制)?
附属性:
public static readonly DependencyProperty DefaultControlProperty = DependencyProperty.RegisterAttached(
"DefaultControl",
typeof(object),
typeof(FocusExtension),
new PropertyMetadata(null));
public static object GetDefaultControl(DependencyObject obj)
{
return (object)obj.GetValue(DefaultControlProperty);
}
public static void SetDefaultControl(DependencyObject obj, object value)
{
obj.SetValue(DefaultControlProperty, value);
}
试试这个:
FocusAfterBusy="{Binding Path=Content.(ext:FocusExtension.DefaultControl),
ElementName=MainRegion}"
我有一个模块化的 WPF 应用程序 - Shell、模块 1、模块 2、模块 3。 每个模块都有这样定义的视图:
<UserControl>
<TextBox x:Name="DefaultControl"/>
<UserControl.Tag>
<Binding ElementName="DefaultControl"/>
</UserControl.Tag>
</UserControl>
Shell 有 MainView,它使用 WPFToolkit BusyIndicator 控件。 MainView 是这样定义的:
<Window>
<xctk:BusyIndicator IsBusy="{Binding ElementName=MainRegion, Path=Content.DataContext.IsBusy}"
FocusAfterBusy="{Binding Path=Content.Tag, ElementName=MainRegion}">
<ContentControl x:Name="MainRegion">
</ContentControl>
</xctk:BusyIndicator>
</Window>
BusyIndicator.FocusAfterBusy 用于在 IsBusy 变为 False 时将焦点设置在任何名为 DefaultControl 的视图元素上。 使用 Tag 属性 绑定时效果很好。 但是现在我想为此使用一个名为 DefaultControl (object) 的简单附加 属性。 视图变为:
<UserControl>
<TextBox x:Name="DefaultControl"/>
<ext:FocusExtension.DefaultControl>
<Binding ElementName="DefaultControl"/>
</ext:FocusExtension.DefaultControl>
</UserControl>
我应该如何更改 BusyIndicator.FocusAfterBusy="{Binding Path=Content.Tag, ElementName=MainRegion}" 中的路径以绑定到 MainRegion.Content 的附件 属性(默认控制)? 附属性:
public static readonly DependencyProperty DefaultControlProperty = DependencyProperty.RegisterAttached(
"DefaultControl",
typeof(object),
typeof(FocusExtension),
new PropertyMetadata(null));
public static object GetDefaultControl(DependencyObject obj)
{
return (object)obj.GetValue(DefaultControlProperty);
}
public static void SetDefaultControl(DependencyObject obj, object value)
{
obj.SetValue(DefaultControlProperty, value);
}
试试这个:
FocusAfterBusy="{Binding Path=Content.(ext:FocusExtension.DefaultControl),
ElementName=MainRegion}"