多数据触发器不起作用?

发布于 2024-12-11 21:35:40 字数 2978 浏览 0 评论 0原文

我想为我的 TabControl 配备一个 MultiDataTrigger。当选项卡悬停时,它应该改变颜色。但如果选择了选项卡则不会。我尝试了多数据触发器。但这似乎不起作用。这是我的风格:

<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabItem}">
            <Grid>
                <Border Name="Border" BorderBrush="Black" BorderThickness="0.5,0.5,0.5,0" CornerRadius="4,4,0,0">
                    <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/>
                </Border>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#fefeff" Offset="0" />
                                <GradientStop Color="#e7edf6" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <Trigger Property="IsSelected" Value="False">
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#c5d0df" Offset="0" />
                                <GradientStop Color="#aab4c2" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=IsMouseOver}" Value="True" />
                        <Condition Binding="{Binding Path=IsSelected}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#dde6f2" Offset="0" />
                                <GradientStop Color="#c6d0de" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </MultiDataTrigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

有什么问题吗?

I want to have a MultiDataTrigger for my TabControl. When the tab is hovered it should change the color. But not if the Tab is selected. I tried a MultiDataTrigger. But it does not seem to work. Here is my Style:

<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabItem}">
            <Grid>
                <Border Name="Border" BorderBrush="Black" BorderThickness="0.5,0.5,0.5,0" CornerRadius="4,4,0,0">
                    <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/>
                </Border>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#fefeff" Offset="0" />
                                <GradientStop Color="#e7edf6" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <Trigger Property="IsSelected" Value="False">
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#c5d0df" Offset="0" />
                                <GradientStop Color="#aab4c2" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=IsMouseOver}" Value="True" />
                        <Condition Binding="{Binding Path=IsSelected}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <Setter TargetName="Border" Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="#dde6f2" Offset="0" />
                                <GradientStop Color="#c6d0de" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </MultiDataTrigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

Is there something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

俏︾媚 2024-12-18 21:35:40

将触发器更改为:

<MultiTrigger.Conditions>
    <Condition Property="IsSelected" Value="false"/>
    <Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>

根据AngelWPF的回答,DataTrigger将尝试绑定到当前的 DataContext,它将在其中找不到与属性匹配的内容。

Change your trigger to be:

<MultiTrigger.Conditions>
    <Condition Property="IsSelected" Value="false"/>
    <Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>

As per AngelWPF's answer a DataTrigger will attempt to bind to the current DataContext, where it will find nothing matching the properties.

注定孤独终老 2024-12-18 21:35:40

DataTriggers 使用DataContext 作为源。我确信 IsMouseOverIsSelected 不是数据上下文中的属性,它们是选项卡项的属性。

我建议使用普通的 MultiTrigger 和普通的 Trigger Condition

DataTriggers use the DataContext as the source. And I am sure that IsMouseOver and IsSelected are not properties from your data context, they are properties of the tab item.

I suggest use normal MultiTrigger with normal Trigger Conditions in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文