WPF DataTrigger没有在NotifyProperyChanged上触发?

时间:2017-03-15 11:45:32

标签: c# wpf datatrigger

我正在尝试根据绑定它的对象中的布尔标志动态隐藏我的ComboBox中的元素,但我似乎无法让它工作

这是我的XAML

SEARCH_DIR

该类绑定到控件

<xctk:CheckComboBox Name="TagsDropDown" HorizontalAlignment="Left" Height="30" Margin="0,0,0,0" VerticalAlignment="Top" Width="450" IsEditable="True"  IsTextSearchEnabled="True" ItemsSource="{Binding AllTags}" ItemSelectionChanged="TagsDropDown_OnItemSelectionChanged">  
        <xctk:CheckComboBox.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Stretch">
                    <TextBlock Margin="2" Text="{Binding Name}"/>
                    <TextBlock Margin="2" HorizontalAlignment="Right" Text="{Binding Count}"/>
                </Grid>
            </DataTemplate>              
        </xctk:CheckComboBox.ItemTemplate>
        <xctk:CheckComboBox.ItemContainerStyle>
            <Style TargetType="xctk:SelectorItem">
                <Setter Property="Visibility" Value="Visible"/>
                <Style.Triggers>
                 <!--   <DataTrigger steamTools:TriggerTracing.TriggerName="is zero" steamTools:TriggerTracing.TraceEnabled="True" Binding="{Binding Path=IsZero, RelativeSource={RelativeSource Self} }" Value="True">-->
                    <DataTrigger Binding="{Binding Path=IsZero, RelativeSource={RelativeSource Self} }" Value="True">
                        <DataTrigger.Setters>
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger.Setters>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </xctk:CheckComboBox.ItemContainerStyle>
    </xctk:CheckComboBox>

谁能看到我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

你的AllTags列表是否有isZero成员?(在模型中)

如果是的话

试试这个

Binding="{Binding Path=IsZero, {RelativeSource FindAncestor, AncestorType={x:Type xctk:CheckComboBox}} }"

如果不是,那么在你的datacontext类中尝试删除RelativeSource={RelativeSource Self}