我正在开发一个avalonia wpf 应用程序,并且我注册了一个 AttachedProperty“IsFocused”,如下所示:
public class FocusExtension
{
public static readonly AttachedProperty<bool> IsFocusedProperty =
AvaloniaProperty.RegisterAttached<Control, bool>("IsFocused", typeof(FocusExtension));
public static bool GetIsFocused(Control element)
{
return element.GetValue(IsFocusedProperty);
}
public static void SetIsFocused(Control element, bool value)
{
element.SetValue(IsFocusedProperty, value);
OnIsFocusedPropertyChanged(element, value);
}
private static void OnIsFocusedPropertyChanged(
Control element,
bool e)
{
if (e)
{
element.Focus();
}
}
}
并像这样在xaml中应用它:
<Button Content="Test" u:FocusExtension.IsFocused="{Binding SomeBoolPropertyInViewModel}"/>
但是当我的 ViewModel 将“SomeBoolPropertyInViewModel”设置为 true 时,它似乎不起作用,
有人可以给我一个例子或提示来实施这项工作吗?谢谢。