简体   繁体   中英

ControlTemplate DataTrigger is not fired in ItemsControl ControlTemplate

I have a NavigationMenuControl with an ObservableCollection<HtNavigationMenuQuickLinkItem> . Everything is working fine, but the Style on my HtMenuIcon Control is not triggered. Where the Visibility is changed correctly. Can someone please give me a hint where I have a mistake? QuickLinkSymbol is a DependencyProperty of an Enum . I also want to put the Visibility Behavior into the DataTrigger section.

Navigation Menu

<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>

QuickLinkItem

<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>

You need to reference Home as {x:Static EnumNAmeSpace:EnumType.Home}.

Oh, and if QuickLinkSymbol is a DepProp of HtNavigationMenuQuickLinkItem,

just use Trigger instead of DataTrigger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM