【问题标题】:Optionally apply multiple styles可选择应用多种样式
【发布时间】:2016-04-28 21:33:51
【问题描述】:

假设我有一个极其简化的 xaml,如下所示:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="converter" />
        <Style TargetType="FrameworkElement" x:Key="maybeCollapsed">
            <Setter Property="Visibility" Value="{Binding Collapsed, Converter={StaticResource converter}}" />
        </Style>
    </UserControl.Resources>
    <StackPanel>
        <Label FontWeight="Bold" Content="Header" x:Name="Header" />
        <TextBox Text="Name" Style="{StaticResource maybeCollapsed}" />
        <TextBox Text="{Binding Name1}" Style="{StaticResource maybeCollapsed}"/>
    </StackPanel>
</UserControl>

如何将第二种样式应用于所有使用maybeCollapsed 样式的元素,将IsTabStop 设置为False?我不能在样式本身中这样做,因为IsTabStop 不是FrameworkElements 的成员。

【问题讨论】:

    标签: wpf xaml targettype


    【解决方案1】:

    改用Control.IsTabStop

     <Style TargetType="FrameworkElement" x:Key="maybeCollapsed">
            <Setter Property="Visibility" Value="{Binding Collapsed, Converter={StaticResource converter}}" />
            <Setter Property="Control.IsTabStop" Value="False" />
        </Style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-29
      • 2011-11-28
      • 2013-12-07
      • 2022-06-29
      • 1970-01-01
      • 2012-04-01
      • 2012-05-29
      • 2011-02-18
      相关资源
      最近更新 更多