XamlX
XamlX copied to clipboard
Add x:Shared attribute support
https://docs.microsoft.com/en-US/dotnet/desktop-wpf/xaml-services/xshared-attribute
This should enable setting attached behaviors from styles and probably enable setting ContextMenu from style too.
Current status:
<Style Selector="TextBlock">
<Setter Property="(i:Interaction.Behaviors)">
<i:BehaviorCollection>
<behaviors:CheckParent/>
</i:BehaviorCollection>
</Setter>
</Style>
Error:
System.InvalidOperationException: An instance of a behavior cannot be attached to more than one object at a time.
at Avalonia.Xaml.Interactivity.BehaviorCollection.Attach(AvaloniaObject associatedObject)
Solution:
<Style Selector="TextBlock" x:Shared="False">
<Setter Property="(i:Interaction.Behaviors)">
<i:BehaviorCollection>
<behaviors:CheckParent/>
</i:BehaviorCollection>
</Setter>
</Style>
Reference:
https://docs.microsoft.com/en-US/dotnet/desktop-wpf/xaml-services/xshared-attribute
Looks like there is already issue in Avalonia https://github.com/AvaloniaUI/Avalonia/issues/2735