我有一个 ListView,您可以在下面的代码中看到:
<ListView Grid.Row="2" MinHeight="75" x:Name="_lstvSearch" ItemsSource="{Binding Search.SearchExpressions}">
<ListView.View>
<GridView>
<GridViewColumn Header="Field name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="True" ItemsSource="{Binding DataContext.Fields,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}"
SelectedItem="{Binding Field, Mode=TwoWay}"
DisplayMemberPath="Field.UserFriendlyFieldName"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Operator">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="True" ItemsSource="{Binding Field.Operators}"
SelectedItem="{Binding Operator, Mode=TwoWay}"
DisplayMemberPath="Operator"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value">
<GridViewColumn.CellTemplateSelector>
<vm:FieldValueTemplateSelector>
<vm:FieldValueTemplateSelector.Alpha>
<DataTemplate>
<TextBox Text="{Binding Value}"/>
</DataTemplate>
</vm:FieldValueTemplateSelector.Alpha>
<vm:FieldValueTemplateSelector.Numeric>
<DataTemplate>
<igEditors:XamNumericEditor Value="{Binding Value}" />
</DataTemplate>
</vm:FieldValueTemplateSelector.Numeric>
<vm:FieldValueTemplateSelector.CheckBox>
<DataTemplate>
<CheckBox IsChecked="{Binding Value}"/>
</DataTemplate>
</vm:FieldValueTemplateSelector.CheckBox>
<vm:FieldValueTemplateSelector.DateTime>
<DataTemplate>
<igEditors:XamDateTimeEditor Value="{Binding Value}" />
</DataTemplate>
</vm:FieldValueTemplateSelector.DateTime>
<vm:FieldValueTemplateSelector.DropDownItem>
<DataTemplate>
<ComboBox ItemsSource="{Binding Value}"/>
</DataTemplate>
</vm:FieldValueTemplateSelector.DropDownItem>
<vm:FieldValueTemplateSelector.Generic>
<DataTemplate>
<TextBox Text="{Binding Value}"/>
</DataTemplate>
</vm:FieldValueTemplateSelector.Generic>
</vm:FieldValueTemplateSelector>
</GridViewColumn.CellTemplateSelector>
</GridViewColumn>
<GridViewColumn Header="AND/OR">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="True" ItemsSource="{Binding DataContext.ConditionLinks,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}"
SelectedItem="{Binding BooleanOperator, Mode=TwoWay}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Remove">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Remove" IsEnabled="{Binding IsValid}" Tag="{Binding}" Click="Button_Click"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我的问题是我不想根据从第一列字段名称中的选择来更改值列中的 CellTemplate,但是我该如何触发它。
选择字段后,我的模型 cald FieldDatatype 中有一个属性,我从中确定第一列中选择的字段的类型。正如您在Value列中看到的那样,我设置了一个 CellTemplateSelector(FieldValueTemplateSelector) ,但是这个设置只有一次数据模板,并且当我从第一列中选择其他字段时不会刷新。