I have a DataGrid
. I want to decide when to collapse a column and when to show it.
This is my code:
<UserControl.Resources>
<ResourceDictionary>
<FrameworkElement x:Key="ProxyElement" DataContext="{Binding}" />
</ResourceDictionary>
<UserControl.Resources>
<DataGridTextColumn.Visibility>
<MultiBinding Converter="{StaticResource MyMultiValueConverter}">
<Binding Source="{StaticResource ProxyElement}" Path="DataContext.MyPropertyInViewModel" />
<Binding Source="1"/>
</MultiBinding>
</DataGridTextColumn.Visibility>
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//Do the conversion
}
I need the proxy element to access the view model from an element that doesn't belong to the visual tree.
In the MultiBinding
, the second binding works. In the converter I receive the value 1
, but the problem is with the first element. I don't get the property of the view model, that it is a string
. I get a DependencyProperty.UnsetValue
.
How can I pass a property of my view model to the multi-value converter?