I'm using XAML to set a style for objects of type "LayoutAnchorableItem". This class contains a property "Model" of type object. I would like to convert this to type IVisible in XAML using an IValueConverter:
public class LayoutAnchorableItem
{
object Model { get; }
// .. other properties & methods ..
}
public interface IVisible
{
bool isVisible { get; set; }
// .. other properties ..
}
public class ObjectToIVisibleConverter : IValueConverter
{
// ...
// "Converts" LayoutAnchorableItem.Model to IVisible by looking up the model's reference in an internal dictionary
}
Then, I would like to use the resulting IVisible-object and databind its isVisible-property to my style setters:
<ad:DockingManager.LayoutItemContainerStyleSelector>
<view:PanesStyleSelector>
<view:PanesStyleSelector.ToolStyle>
<Style TargetType="{x:Type ad:LayoutAnchorableItem}">
<!-- PSEUDO-CODE! I cant use {Binding ...} inside a {Binding ...} -->
<Setter Property="Visibility" Value="{Binding {Binding Model, Converter={StaticResource ObjectToIVisibleConverter}}.isVisible, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Style>
</view:PanesStyleSelector.ToolStyle>
</view:PanesStyleSelector>
</ad:DockingManager.LayoutItemContainerStyleSelector>
But how can I do this in XAML?
I've only ever seen examples of how IValueConverters convert complex objects to basic types (string, double etc.) - but can I also use it to convert an object to another object of different type, and then bind to one of its properties?
Otherwise, is there any other way do to this? I've thought about including another , but that didn't work out either (plus changing the entire element's DataContext may not be very smart...).
As for why I'm doing this: This is a style settler for an AvalonDock Element. My view models don't contain any AvalonDock-specific properties (such as isVisible) though, so I need to store them seperately, e.g. in a Dictionary< object, IExtendedLayoutInformation >. For databinding, I'm trying to convert the viewmodel (LayoutAnchorableItem.Model) to IExtendedLayoutInformation by looking it up in my dictionary, and then need to bind to the fields of this IExtendedLayoutInformation object.