【问题标题】:Make correct display selected elements for any OS (WPF)为任何操作系统 (WPF) 正确显示所选元素
【发布时间】:2013-02-26 21:23:22
【问题描述】:

我有列表视图

 <ListView x:Name="listView">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="800" >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Display}"  Foreground="Black" >
                                </TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="800" >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Display}"  />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

第一个文本块 - Foreground="Black" 第二个 TextBlock - 未指定前景。

在 ListView 中的选定项目中,第一个 TextBlock foreground="Black"(在每个操作系统中都显示不正确),第二个 TextBlock - 前景默认(在每个操作系统中正确显示)。

我需要什么:

在 ListView 中的选定项目中,第一个 TextBlock 前景也必须是默认的,并且在每个操作系统中都正确显示,但我无法直接更改 TextBlock 前景(在触发器或样式中)。

有什么想法吗?也许我可以重置第一个 TextBlock 的前景(没有设置默认前景!完全重置)。还是将样式重置为默认??

【问题讨论】:

  • 对不起,我不明白 - 什么是操作系统??

标签: c# wpf


【解决方案1】:

不确定我的问题是否正确,但这是我的猜测:您不能更改第一个 TextBlockForeground,因为它是明确设置的。只需从控件本身中删除前景定义并将其设置为样式,这应该使其可以被其他样式和触发器覆盖。

有更多详细信息的答案(例如this one),因此您的问题有些重复。好吧,如果我做对了 =)

【讨论】:

    猜你喜欢
    • 2016-07-10
    • 2017-02-16
    • 2014-09-17
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    相关资源
    最近更新 更多