Wpf datatemplate未在datatrigger上切换

Wpf datatemplate未在datatrigger上切换,wpf,datatemplate,Wpf,Datatemplate,我已经为我的listBox定义了两个datatemplates,我使用DataTemplateSelector来决定为一个项目呈现哪一个。但是,我的一个模板有一个嵌入式按钮,单击该按钮时,应该会在适当的位置显示一个表单。因此,我设置了一个布尔属性并实现了INotifyPropertyChanged;因此,当布尔属性为true时,当前模板将替换为第三个模板 这是按钮的代码 Activity activityItem = (Activity)listBox1.Items[listBo

我已经为我的listBox定义了两个datatemplates,我使用DataTemplateSelector来决定为一个项目呈现哪一个。但是,我的一个模板有一个嵌入式按钮,单击该按钮时,应该会在适当的位置显示一个表单。因此,我设置了一个布尔属性并实现了INotifyPropertyChanged;因此,当布尔属性为true时,当前模板将替换为第三个模板

这是按钮的代码

        Activity activityItem = (Activity)listBox1.Items[listBox1.SelectedIndex]; 
        activityItem.ShowFeedbackForm = 1;
这是我的XAML:

    <Grid.Resources>
    <DataTemplate x:Key="completedActivityTemplate">
        <Grid Name="templateGrid" >
    ... 
    <DataTemplate x:Key="activityTemplate">
        <Grid Name="templateGrid" >
    ...
    <DataTemplate x:Key="feedbackFormTemplate">
        <Grid Name="templateGrid" >
    ...    
     <Style TargetType="ListBoxItem" x:Key="ContainerStyle">
        <Setter Property="Height" Value="55" />
        <Setter Property="Background" Value="Transparent" />
        <Style.Triggers>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="IsSelected" Value="True" />
            </Trigger>
            <DataTrigger Binding="{Binding showFeedbackForm}" Value="1">
                <Setter Property="ContentTemplate" Value="{StaticResource feedbackFormTemplate}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    </Grid.Resources>
    <ListBox Grid.Row="1" Name="listBox1" IsSynchronizedWithCurrentItem="True" 
         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
         VerticalContentAlignment="Stretch" Background="Transparent"
         BorderThickness="0" ItemContainerStyle="{StaticResource ContainerStyle}"
         HorizontalContentAlignment="Stretch" Margin="-3,0,0,0"
         ItemTemplateSelector="{StaticResource myDataTemplateSelector}">
    </ListBox>

... 
...
...    

因此,当用户单击该按钮时,该项的ShowFeedbackForm的值设置为1,即显示反馈表单的模板将被显示,但什么也没有发生。我的ObservableCollection(单向)绑定工作正常。

在按钮单击处理程序中,我设置绑定项的布尔值,然后重新绑定listBox的datatemplate选择器

        ListBoxItem currentItem = (ListBoxItem)(listBox1.ItemContainerGenerator.ContainerFromItem(listBox1.Items.CurrentItem));
        Activity activityItem = (Activity)listBox1.Items[listBox1.SelectedIndex]; 
        activityItem.ShowFeedbackForm = 1;
        listBox1.ItemTemplateSelector = new ActivityFeedDataTemplateSelector();
如果设置了布尔值,My ActivityFeedDataTemplateSelector将返回所需的模板名称