[RESOLVED] AttachedProperties [Unity]
Posted: 05 Dec 2013, 09:00
I'm looking for a way to define attached property in NoesisGUI 1.1.2 Unity3D. In WPF is code like this:
I've tried to register attached property in NoesisGUI as DependencyProperty (as described in docs), and it seems to work except I can't find the way to add callback handler to handle event when this property was attached to FrameworkElement. Is there any way to achieve it in the NoesisGUI?
Code: Select all
public class TestClass: DependencyObject
{
public static readonly DependencyProperty PropNameProperty =
DependencyProperty.RegisterAttached(
"PropName",
typeof(object),
typeof(TestClass),
new FrameworkPropertyMetadata(null, PropertyChangedCallback));
private static void PropertyChangedCallback(
DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs args)
{
FrameworkElement fe = dependencyObject as FrameworkElement;
if (fe == null) return;
// property was assigned/removed from FrameworkElement
// so we can do something useful here
}
public static object GetPropName(UIElement element)
{
return element.GetValue(PropNameProperty);
}
public static void SetPropName(UIElement element, object value)
{
element.SetValue(PropNameProperty, value);
}
}