我有一个模块化的WPF应用程序- Shell, Module1, Module2, Module3。每个模块都有如下定义的视图:
<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。当IsBusy变为False时,FocusAfterBusy将焦点设置在任何名为DefaultControl的视图元素上。当使用Tag属性进行绑定时,它工作得很好。但现在我想使用一个简单的附加属性名为DefaultControl (object)。视图变成如下:
<UserControl>
<TextBox x:Name="DefaultControl"/>
<ext:FocusExtension.DefaultControl>
<Binding ElementName="DefaultControl"/>
</ext:FocusExtension.DefaultControl>
</UserControl>
如何在BusyIndicator.FocusAfterBusy="{Binding Path=Content中更改路径?标签,ElementName=MainRegion}",以绑定到MainRegion。内容的附加属性(DefaultControl)?附加属性:
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}"