Can an attached property be defined in a different assembly than the one it is used in?
Posted: 22 Aug 2019, 22:43
I have the following attached property which works fine if it's defined locally...
But then when I move it to an assembly "NoesisHelpers" and try to use it in my XAML by referencing that assembly, it doesn't work:
Is that expected?
Code: Select all
public static class FocusExtension
{
public static bool GetIsFocused(DependencyObject obj)
{
return (bool)obj.GetValue(IsFocusedProperty);
}
public static void SetIsFocused(DependencyObject obj, bool value)
{
obj.SetValue(IsFocusedProperty, value);
}
public static readonly DependencyProperty IsFocusedProperty =
DependencyProperty.RegisterAttached(
"IsFocused", typeof(bool), typeof(FocusExtension),
new UIPropertyMetadata(false, OnIsFocusedPropertyChanged));
private static void OnIsFocusedPropertyChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
var uie = (UIElement)d;
if ((bool)e.NewValue)
{
uie.Focus(); // Don't care about false values.
}
}
}
But then when I move it to an assembly "NoesisHelpers" and try to use it in my XAML by referencing that assembly, it doesn't work:
Code: Select all
xmlns:nh="clr-namespace:NoesisHelpers;assembly=NoesisHelpers"
...
<Grid Name="tvRootGrid" nh:FocusExtension.IsFocused="{Binding Path=IsFocused}">
Is that expected?