I'm trying to use AvalonDock with MVVM and disabling the hide feature of a LayoutAnchorable
. Without MVVM, I can do something like:
<xcad:LayoutAnchorable CanHide="False">
<TextBox>Some Content</TextBox>
</xcad:LayoutAnchorable>
The CanHide="False"
disables hiding.
How can I access the CanHide
property using MVVM or disable hiding in another way?
I have:
<xcad:DockingManager AnchorablesSource="{Binding UserPanelList}">
<xcad:DockingManager.LayoutItemContainerStyle>
<Style TargetType="xcad:LayoutItem">
<Setter Property="Title" Value="{Binding Model.Title}" />
<Setter Property="ContentId" Value="{Binding Model.ContentId}" />
</Style>
</xcad:DockingManager.LayoutItemContainerStyle>
<xcad:DockingManager.LayoutItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Control}" />
</DataTemplate>
</xcad:DockingManager.LayoutItemTemplate>
<xcad:LayoutRoot>
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePane>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
And a completely trivial model class:
public class UserPanel : INotifyPropertyChanged
{
public string Title { get; set; }
public string ContentId { get; set; }
public bool CanHide { get; set; } // ??
// (NotifyPropertyChanged not implemented for these properties here
// for the sake of brevity. Basically works without.)
public UserControl Control
{
get => _userInterface;
set
{
if (value != _userInterface)
{
_userInterface = value;
OnPropertyChanged();
}
}
}
UserControl _userInterface;
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
The view classes are created from the contents of the bound UserPanelList
.
However, the LayoutItem
class does not contain a CanHide
property, i.e. I cannot use a <Setter>
afaik. What can I do instead?
The class LayoutAnchorableItem
that derives from LayoutItem
is used for LayoutAnchorable
s (see e.g. here). It has a dependency property CanHide
that works as expected.
On can set the style for LayoutAnchorableItem
either by
<Style TargetType="xcad:LayoutAnchorableItem">
<!-- ... -->
<Setter Property="CanHide" Value="{Binding Model.CanHide}" />
or, more flexible, by
<Style TargetType="xcad:LayoutItem">
<!-- ... -->
<Setter Property="xcad:LayoutAnchorableItem.CanHide" Value="{Binding Model.CanHide}" />