我有一个NavigationMenuControlObservableCollection<HtNavigationMenuQuickLinkItem>。一切正常,但未触发我的Style控件上的HtMenuIconVisibility正确更改的位置。有人可以给我提示我哪里有错误吗? QuickLinkSymbolDependencyPropertyEnum
我还想将可见性行为放入DataTrigger部分。

导航菜单

<Style TargetType="Navigation:HtNavigationMenu">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Navigation:HtNavigationMenu">
                <Grid>
                    <StackPanel Orientation="Vertical">
                        <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=QuickLinkItems}"/>
                    </StackPanel>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


快速链接项

<Style TargetType="Navigation:HtNavigationMenuQuickLinkItem">
    <Style.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVis"/>
    </Style.Resources>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Navigation:HtNavigationMenuQuickLinkItem">
                <Controls:MyButton Width="40" Height="40" Margin="10,10,10,0">
                    <Viewbox Margin="3">
                        <Controls:HtMenuIcon x:Name="icon" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsQuicklink, Converter={StaticResource BoolToVis}}"/>
                    </Viewbox>
                </Controls:MyButton >
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding QuickLinkSymbol, RelativeSource={RelativeSource TemplatedParent}}" Value="Home">
                        <Setter TargetName="icon" Property="Style" Value="{StaticResource Home}"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

最佳答案

您需要将Home引用为{x:Static EnumNAmeSpace:EnumType.Home}。

哦,如果QuickLinkSymbol是HtNavigationMenuQuickLinkItem的DepProp,

只需使用Trigger而不是DataTrigger。

关于c# - 未在ItemsControl中触发ControlTemplate DataTrigger,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42898718/

10-10 10:58