【问题标题】:DataTrigger only works on first TabItem in TabControlDataTrigger 仅适用于 TabControl 中的第一个 TabItem
【发布时间】:2011-01-28 12:12:58
【问题描述】:

这似乎是 WPF 中的一个错误,但也许有人对此有答案。 我有一个可编辑组合框的 DataTrigger。它适用于我的 TabControl 的第一个 TabItem,但不适用于第二个。如果您将第一个与第二个 TabItem 切换,则“第二个”将起作用。当您将样式完全赋予 ComboBox (ComboBox.Style ...) 时,也会发生相同的效果。

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="Height" Value="25" />
        <Setter Property="Width" Value="125" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=PART_EditableTextBox, Path=IsFocused}" Value="True">
                <Setter Property="BitmapEffect">
                    <Setter.Value>
                        <OuterGlowBitmapEffect GlowColor="Red" GlowSize="5" />
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
    <TabControl>
        <TabItem Header="TabItem1">
            <Grid>
                <ComboBox IsEditable="True"/>
            </Grid>
        </TabItem>
        <TabItem Header="TabItem2">
            <Grid>
                <ComboBox IsEditable="True"/>
            </Grid>
        </TabItem>
    </TabControl>
</Grid>

【问题讨论】:

    标签: wpf combobox tabcontrol datatrigger


    【解决方案1】:

    好像是个bug

    改为使用:

    Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="BitmapEffect">
                        <Setter.Value>
                            <OuterGlowBitmapEffect GlowColor="Red" GlowSize="5" />
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多