XamlX icon indicating copy to clipboard operation
XamlX copied to clipboard

Add x:Shared attribute support

Open wieslawsoltes opened this issue 3 years ago • 1 comments

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

wieslawsoltes avatar Aug 07 '20 06:08 wieslawsoltes

Looks like there is already issue in Avalonia https://github.com/AvaloniaUI/Avalonia/issues/2735

wieslawsoltes avatar Aug 07 '20 09:08 wieslawsoltes