首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >是否在WPF中优先设置优先级?

是否在WPF中优先设置优先级?
EN

Stack Overflow用户
提问于 2009-10-18 10:33:09
回答 2查看 2K关注 0票数 2

请看下面示例中的行"THIS line ####“。

代码语言:javascript
运行
AI代码解释
复制
<ListBox Grid.Row="0" x:Name="listBoxServers">
<ListBoxItem HorizontalContentAlignment="Stretch">
    <StackPanel>
        <TextBlock><Run Text="My computer"/></TextBlock>
        <TextBlock Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
            <TextBlock.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="True">
                            <Setter Property="TextBlock.Foreground" Value="White" /> <!-- THIS LINE #### How can I get this work? -->
                            <Setter Property="TextBlock.Background" Value="Blue" /> <!-- This line here for debugging purposes (to show that these really are called) -->
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
            <Run Text="localhost"/>
        </TextBlock>
    </StackPanel>
</ListBoxItem>
</ListBox>

如何让下面的触发器覆盖该值?

(顺便说一句,上面的例子只是压缩的。(在实际应用中,样式在它自己的资源中。)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-10-18 10:43:41

您应该能够使用两个数据触发器来完成此操作,一个用于true,一个用于false。

代码语言:javascript
运行
AI代码解释
复制
    <TextBlock>
        <TextBlock.Style>
            <Style>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="True">
                        <Setter Property="TextBlock.Foreground" Value="White" />
                        <Setter Property="TextBlock.Background" Value="Blue" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="False">
                        <Setter Property="TextBlock.Foreground" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
        <Run Text="localhost"/>
    </TextBlock>
票数 2
EN

Stack Overflow用户

发布于 2009-10-18 21:32:27

This post可能会解释为什么当您为该属性分配了一个本地值时,触发器不会触发。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1585670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文