ToggleMenuFlyoutItem基于Checked的文本更改?

时间:2017-11-09 16:35:56

标签: xaml uwp-xaml

我添加了

ToggleMenuFlyoutItem Text ="销售税免税"点击=" btnTaxExempt_Click"

而不是打开时的复选标记和关闭时没有复选标记,我想更改文本以读取"免税打开"或者"免税豁免"。我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以更新ToggleMenuFlyoutItem styles and templates以隐藏display: inline-block FontIcon到CheckGlyph并根据需要更新后面的文本代码。例如:

XAML

Collapsed

代码背后:

<Style x:Key="ToggleMenuFlyoutItemStyle1" TargetType="ToggleMenuFlyoutItem">   
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleMenuFlyoutItem">
                    <Grid x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                        <VisualStateManager.VisualStateGroups>
                         ...
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="AnimationRoot">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <FontIcon x:Name="CheckGlyph" Visibility="Collapsed" Foreground="{ThemeResource ToggleMenuFlyoutItemCheckGlyphForeground}" FontSize="16" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE001;" Margin="0,0,12,0" Opacity="0" Width="16"/>
                            <TextBlock x:Name="TextBlock" Grid.Column="1" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Text}" TextTrimming="Clip" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

 <ToggleMenuFlyoutItem Text="Sales Tax Exempt" Click="btnTaxExempt_Click" Style="{StaticResource ToggleMenuFlyoutItemStyle1}" ></ToggleMenuFlyoutItem>

ToggleMenuFlyoutItem应在MenuFlyout内使用,如果您不使用private void btnTaxExempt_Click(object sender, RoutedEventArgs e) { ToggleMenuFlyoutItem current = sender as ToggleMenuFlyoutItem; if(current.IsChecked) { current.Text = "Tax Exempt On"; } else if(!current.IsChecked) { current.Text = "Tax Exempt Off"; } } ,则可以考虑使用ToggleSwitchMenuFlyout很容易设置OnContentOffContent