WPF 列表框选择颜色
很抱歉,如果之前有人问过这个问题,但我无法在弹出的相关问题或 Google 上找到我正在寻找的解决方案。
在我的应用程序中,我尝试重新创建 Words 新文档对话框,在项目左侧列出,在右侧列出下面带有文本的图标。 在 Word 中,当您将鼠标悬停在其上时,它会呈现橙色渐变;而当您选择某个项目时,它会呈现较暗的渐变。 我已经重新创建了大部分内容,除了在选择项目后更改背景颜色之外。 这是我用来创建这个的代码:
<ListView Margin="236,34,17,144" Name="listView1" HorizontalContentAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" IsItemsHost="True" VerticalAlignment="Top" >
</UniformGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate >
<StackPanel HorizontalAlignment="Center" Width="auto">
<Image Source="images/document32.png" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding}" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="Yellow" />
<Setter Property="Background" Value="Orange" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Black" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="1,0">
<GradientStop Color="#d3e7ff" Offset="0.986"/>
<GradientStop Color="#b0d2fc" Offset="0.5"/>
<GradientStop Color="#8ec1ff" Offset="0.51"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
所以这创建了我想要的外观,将鼠标悬停在上面,当我在列表视图中选择一个项目时,它会将字体文本更改为黄色,但它拒绝更改背景从默认的蓝色到橙色,理想情况下无论如何它都是另一个渐变而不是填充颜色。 谢谢你的帮助。
Sorry if this has been asked before, but I couldn't find a solution to what I'm looking for in the related questions that popped up, or on Google.
In my application I'm trying to recreate Words New Document dialog, list on the left of items and on the right an icon with text underneath. In Word it has the orange gradient when you mouse over, and a darker gradient when you select an item. I've got most of this recreated, except for changing the background color once you select an item. Here's the code I'm using to create this:
<ListView Margin="236,34,17,144" Name="listView1" HorizontalContentAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" IsItemsHost="True" VerticalAlignment="Top" >
</UniformGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate >
<StackPanel HorizontalAlignment="Center" Width="auto">
<Image Source="images/document32.png" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding}" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="Yellow" />
<Setter Property="Background" Value="Orange" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Black" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="1,0">
<GradientStop Color="#d3e7ff" Offset="0.986"/>
<GradientStop Color="#b0d2fc" Offset="0.5"/>
<GradientStop Color="#8ec1ff" Offset="0.51"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
So this creates the look I'm going for, does the mouse over, and when I select an item in the listview it will change the fonts text to Yellow, but it refuses to change the background from the default blue to orange, and ideally it would be another gradient anyways and not a floodfilled color. Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行一些技巧,例如覆盖系统颜色键,但您很可能需要提供一个新模板来实现此目的。 这是我整理的一个看起来相当漂亮的:
There are a few hacks you can do like overriding the system color key, but most likely you will want to provide a new template to achieve this. Here's a fairly nice looking one I put together: