I have a CustomBehavior which is working perfect at runtime. Now I also want to have some "behavior" at the DesignMode. But my OnAttached() is not called at DesignMode (https://www.codeproject.com/Tips/1040701/How-to-Debug-the-Design-Time-Errors-in-WPF-XAML-Fi).
public class CustomBehavior : Behavior<FrameworkElement>
{
protected override void OnAttached()
{
if (DesignerProperties.GetIsInDesignMode(this))
{
_TargetProperty = AssociatedObject.GetType().GetProperty(TargetPropertyName);
_DesignMethod();
}
else
{
AssociatedObject.Unloaded += AssociatedObject_Unloaded;
AssociatedObject.Loaded += AssociatedObject_Loaded;
}
}
}
Is there a trick, how to call my _DesignMethod() at DesignMode?
This is currently my solution. But it is not perfect and it would be nice if you could omit the
DesignerElementproperty.To get this working, you need to pass in your
xamlcode the attached object/element. UnfortunatelyLogicalTreeHelperorVisualTreeHelpercannot find my object/element.Abstract Behavior
XAML Usage
Preview