如何使用不同颜色的列表行的选择突出显示? [英] How to make selection highlight of list rows with different colors?
本文介绍了如何使用不同颜色的列表行的选择突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好!
我有一个问题。
如何突出选择行列表以不同的颜色查看?但我想用列表选择器做正确的事。
请提供一些简单的几种颜色
谢谢
Hello!
I have a question.
how to make highlight selection of row in List View by different colors? but I want to do it correct with list selectors.
Please provide some simple for few colors
thank you
推荐答案
你好托马斯,
我想我们可以通过使用WPF应用程序轻松实现这一点:
完整的解决方案如下:
for Start VS2010然后添加一个名为<的新项目wpf_datagrid_propertytriggers>使用WPF应用程序:
然后在MainWindow.xmal中添加此代码
---
hello thomas,
I think We Can Easily do this by using WPF Application:
the complete solution is below:
for Start VS2010 then Add a new project named as <wpf_datagrid_propertytriggers> using a WPF Application:
then Add This Code in MainWindow.xmal
---
<br />
<Window x:Class="WPF_DataGrid_PropertyTriggers.MainWindow"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
xmlns:src="clr-namespace:WPF_DataGrid_PropertyTriggers"<br />
Title="MainWindow" Height="382" Width="892"><br />
<Window.Resources><br />
<src:EmployeeCollection x:Key="EmpCol"></src:EmployeeCollection><br />
<Style TargetType="{x:Type DataGridCell}"><br />
<Style.Triggers><br />
<DataTrigger Binding="{Binding Designation}" Value="Manager"><br />
<Setter Property="Background" Value="Green"></Setter><br />
</DataTrigger><br />
<DataTrigger Binding="{Binding Designation}" Value="Clerk"><br />
<Setter Property="Background" Value="Red"></Setter><br />
</DataTrigger><br />
<DataTrigger Binding="{Binding Designation}" Value="Supervisor"><br />
<Setter Property="Background" Value="Chocolate"></Setter><br />
</DataTrigger><br />
<DataTrigger Binding="{Binding Designation}" Value="Operator"><br />
<Setter Property="Background" Value="Magenta"></Setter><br />
</DataTrigger><br />
</Style.Triggers><br />
</Style><br />
</Window.Resources><br />
<Grid DataContext="{Binding Source={StaticResource EmpCol}}"><br />
<DataGrid AutoGenerateColumns="True" Height="272" HorizontalAlignment="Left" Margin="43,48,0,0"<br />
Name="dgEmp" VerticalAlignment="Top" Width="652" ItemsSource="{Binding}"<br />
ColumnWidth="*"/><br />
<TextBlock Height="45" HorizontalAlignment="Left" Margin="132,0,0,0"<br />
Name="textBlock1" Text="Employee Infoemation System"<br />
VerticalAlignment="Top" Width="467" OpacityMask="#FF930000"<br />
FontStyle="Oblique" FontWeight="ExtraBold" FontSize="26" TextWrapping="WrapWithOverflow"<br />
TextTrimming="CharacterEllipsis" /><br />
<StackPanel Height="250" HorizontalAlignment="Left" Margin="717,52,0,0" Name="stackPanel1"<br />
VerticalAlignment="Top" Width="125"><br />
<StackPanel Orientation="Horizontal"><br />
<TextBlock Width="80" Text="Manager" FontSize="15"></TextBlock><br />
<Rectangle Fill="Red" Width="44"></Rectangle><br />
</StackPanel><br />
<StackPanel Orientation="Horizontal"><br />
<TextBlock Width="80" Text="Clerk" FontSize="15"></TextBlock><br />
<Rectangle Fill="Yellow" Width="44"></Rectangle><br />
</StackPanel><br />
<StackPanel Orientation="Horizontal"><br />
<TextBlock Width="80" Text="Supervisor" FontSize="15"></TextBlock><br />
<Rectangle Fill="Chocolate" Width="44"></Rectangle><br />
</StackPanel><br />
<StackPanel Orientation="Horizontal"><br />
<TextBlock Width="80" Text="Operator" FontSize="15"></TextBlock><br />
<Rectangle Fill="Magenta" Width="44"></Rectangle><br />
</StackPanel><br />
</StackPanel><br />
<TextBlock Height="35" HorizontalAlignment="Left" Margin="717,11,0,0" Name="textBlock2" Text="Legend" VerticalAlignment="Top" Width="123" FontSize="20" /><br />
</Grid><br />
</Window><br />
<br />
----------- ---------------------
现在添加一个类(.cs文件)名称为< datafiles.cs>
并在该文件中添加以下代码
-
--------------------------------
Now Add A class(.cs file) names As <datafiles.cs>
and Add this below code in that file
--
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Collections.ObjectModel;<br />
<br />
namespace WPF_DataGrid_PropertyTriggers<br />
{<br />
public class Employee<br />
{<br />
public int EmpNo { get; set; }<br />
public string EmpName { get; set; }<br />
public string DeptName { get; set; }<br />
public string Designation { get; set; }<br />
public int Experience { get; set; }<br />
public int Salary { get; set; }<br />
}<br />
<br />
public class EmployeeCollection : ObservableCollection<Employee><br />
{<br />
<br />
public EmployeeCollection()<br />
{<br />
<br />
Add(new Employee() { EmpNo = 101, EmpName = "Ramesh", DeptName = "IT", Designation = "Manager", Experience = 15, Salary = 300000 });<br />
Add(new Employee() { EmpNo = 102, EmpName = "Ajay", DeptName = "Accts", Designation = "Clerk", Experience = 12, Salary = 200000 });<br />
Add(new Employee() { EmpNo = 103, EmpName = "Atul", DeptName = "Tech", Designation = "Supervisor", Experience = 10, Salary = 400000 });<br />
Add(new Employee() { EmpNo = 104, EmpName = "Narayan", DeptName = "Hrd", Designation = "Supervisor", Experience = 14, Salary = 400000 });<br />
Add(new Employee() { EmpNo = 105, EmpName = "Baban", DeptName = "Hrd", Designation = "Manager", Experience = 18, Salary = 300000 });<br />
Add(new Employee() { EmpNo = 106, EmpName = "Mandar", DeptName = "IT", Designation = "Operator", Experience = 12, Salary = 200000 });<br />
Add(new Employee() { EmpNo = 107, EmpName = "Suraj", DeptName = "Accts", Designation = "Operator", Experience = 22, Salary = 200000 });<br />
Add(new Employee() { EmpNo = 108, EmpName = "Chaitanya", DeptName = "Tech", Designation = "Supervisor", Experience = 13, Salary = 400000 });<br />
Add(new Employee() { EmpNo = 109, EmpName = "Anand", DeptName = "Tech", Designation = "Manager", Experience = 16, Salary = 300000 });<br />
Add(new Employee() { EmpNo = 110, EmpName = "Kapil", DeptName = "Hrd", Designation = "Clerk", Experience = 10, Salary = 200000 });<br />
}<br />
}<br />
}<br />
<br />
<br />
-
之后开始调试您的项目。
您将在角色基础上获得具有不同颜色行的窗口..
--
After This Start Debugging your project.
you will get the window with different colors rows on role basis..
参考: Android listview记住选择并设置默认选择 [ ^ ]
这篇关于如何使用不同颜色的列表行的选择突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文