0

I've created an avalon dock interface in my project, I want to interact with a LayoutAnchorableItem property "Visibility" for example but how implement it into my XAML code ? I couldn't have two Style definitions into my DockingManager.LayoutItemContainerStyle branch...

The line I want to add:

<Setter Property="Visibility" Value="{Binding Model.IsVisible, ConverterParameter={x:Static Visibility.Hidden}, Converter={StaticResource btvc}, Mode=TwoWay}" />

My original XAML code:

<dock:DockingManager DataContext="{Binding DockManagerViewModel}" DocumentsSource="{Binding Documents}" AnchorablesSource="{Binding Anchorables}" >
    <dock:DockingManager.Resources>
    <!-- add views for specific ViewModels -->
        <DataTemplate DataType="{x:Type vmdock:SampleDockWindowViewModel}">
            <uscontrol:SampleDockWindowView />
        </DataTemplate>
    </dock:DockingManager.Resources>
    <dock:DockingManager.LayoutItemContainerStyle>
    <!--you can add additional bindings from the layoutitem to the DockWindowViewModel-->
        <Style TargetType="{x:Type dockctrl:LayoutItem}">
            <Setter Property="Title" Value="{Binding Model.Title}" />
            <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
            <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
            <Setter Property="IsSelected" Value="{Binding Model.IsSelected}" />
        </Style>
    </dock:DockingManager.LayoutItemContainerStyle>

Thanks a lot !

Marion
  • 23
  • 4

2 Answers2

1

If you want to select between multiple styles there is a LayoutItemContainerStyleSelector property on the dockingmanager which uses a Style Selector. With this style selector you can choose which style to apply depending if the object is a LayoutAnchorableItem or a different type of LayoutItem.

public class MyStyleSelector : StyleSelector
{

    public Style DefaultStyle { get; set; }
    public Style CustomStyle { get; set; }

    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is LayoutAnchorableItem)
        {
            return CustomStyle;
        }
        return DefaultStyle;
    }

}

If you want to merge the single style setter to the other style you can use the BasedOn property. This works because LayoutAnchorableItem inherits LayoutItem. With this you can make a style based on another style so it inherits all the setters. The resources would look like:

<Style TargetType="{x:Type dockctrl:LayoutItem}" x:Key="DefaultStyle">
  <Setter Property="Title" Value="{Binding Model.Title}" />
  <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
  <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
  <Setter Property="IsSelected" Value="{Binding Model.IsSelected}" />
</Style>

<Style TargetType="{x:Type dockctrl:LayoutAnchorableItem}" BasedOn="{StaticResource DefaultStyle}" x:Key="CustomStyle">
  <Setter Property="Visibility" Value="{Binding Model.IsVisible, ConverterParameter={x:Static Visibility.Hidden}, Converter={StaticResource btvc}, Mode=TwoWay}" />
</Style>

<local:MyStyleSelector DefaultStyle="{StaticResource DefaultStyle}" CustomStyle="{StaticResource CustomStyle}" x:Key="MyStyleSelector" />

Now you can fill in the docking manager with the new style selector.

<dock:DockingManager LayoutItemContainerStyleSelector="{StaticResource MyStyleSelector}" ...

You can leave out the style selector and remove the keys in the resources. Note that these styles will then be applied in all children which is not something you generally want.

Matthias
  • 26
  • 1
  • 3
0

Thanks for your answer! I'm not sure it deals with my problem... what I want is defined a style for an other Target Type, like if I could write :

<Style TargetType="{x:Type dockctrl:LayoutItem}">
[...]
</Style>

<Style TargetType="{x:Type dockctrl:LayoutAnchorableItem}">
  [...]
</Style>

But I couldn't write both style directly into my DockingManager.LayoutItemContainerStyle branch. It accepts only one Style definition... how to deals with that ? Thanks

Marion
  • 23
  • 4