I have an observable collection bound to my ListView via its ItemsSource property. I use a GridView to present the items in the ListView. By setting the "IsServiceMode" property to "true" in my ViewModel (DataContext to UserControl that houses the ListView) i want to change a GridViewColumn to use TextBox instead of Textblock. I'm using CellTemplates with ContentControl and DataTemplate as described here
However, the "Binding Position" in the Textblock and Textbox controls don't seem to work although the Editor is suggesting "Position". Position is a property of the items in the bound ObservableCollection and can be used via DisplayMemberBinding without Problems.
My GridViewColumn
<GridViewColumn Header="Position">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ContentControl>
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsServiceMode, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="False">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Position, diag:PresentationTraceSources.TraceLevel=High}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding DataContext.IsServiceMode, RelativeSource={RelativeSource AncestorType=UserControl}}" Value="True">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBox Text="{Binding Position}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>´´´
Demo