I have a UserControl with its DataContext set to another class called HostConext.
In HostContext I have the following property:
public Visibility IsOutcomesVisible
{
get { return _isOutcomesVisible; }
set { _isOutcomesVisible = value; OnPropertyChanged("IsOutcomesVisible"); }
}
My XAML contains a DataGrid that looks like this:
<dg:DataGrid Grid.Row="0" ItemsSource="{Binding Path=Payments}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Header="Payment Date" Binding="{Binding PaymentDate,StringFormat={}\{0:yyyy/MM/dd\}}"/>
<dg:DataGridComboBoxColumn Header="Outcome" SelectedItemBinding="{Binding Outcome}"
Visibility="{Binding Path=DataContext.IsOutcomesVisible}">
....
</dg:DataGridComboBoxColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
The datagrid's ItemSource is set to an ObservableList of Payment objects and each column binds the properties in it. The problem, however, is that I need to hide (or disable) the Outcomes column based on a property in the UserControl's DataContext.
Does anybody here know how this can be achieved? I really don't want to put the "IsOutcomesVisible" property in the Payments class :(