помогите мне, пожалуйста. У меня есть DataGrid с ComboBoxColumn, и я должен изменить текст переднего плана.
Например: - Если ComboBoxColumn имеет значение "IT", передний план должен быть "красным" - Если ComboBoxColumn имеет значение "R & D", передний план должен быть "желтым" - Если ComboBoxColumn имеет значение «Финансы», передний план должен быть «Черный»
<Page
x:Class="DataGridComboBoxColumnColor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MSControls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:local="using:DataGridComboBoxColumnColor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<MSControls:DataGrid Grid.Column="1"
ItemsSource="{x:Bind Persons}"
AutoGenerateColumns="False"
ScrollViewer.HorizontalScrollMode="Enabled"
RowHeight="60">
<MSControls:DataGrid.Columns>
<MSControls:DataGridTextColumn Header="First
Name" Width="*"
Binding="{Binding FirstName}"/>
<MSControls:DataGridTextColumn Header="Last
Name" Width="*"
Binding="{Binding LastName}"/>
<MSControls:DataGridTextColumn Header="Position"
Width="*"
Binding="{Binding Position}"/>
<MSControls:DataGridComboBoxColumn Header="Department"
Width="*"
Binding="{Binding DepartmentId}"
ItemsSource="{x:Bind Departments}"
DisplayMemberPath="DepartmentName"/>
</MSControls:DataGrid.Columns>
</MSControls:DataGrid>
</Grid>
</Page>
Код позади
namespace DataGridComboBoxColumnColor
{
public class Department
{
public int DepartmentId {
get;
set;
}
public string DepartmentName {
get;
set;
}
}
public class Person
{
public int PersonId {
get;
set;
}
public int DepartmentId {
get;
set;
}
public string FirstName {
get;
set;
}
public string LastName {
get;
set;
}
public string Position {
get;
set;
}
}
public sealed partial class MainPage : Page
{
public List<Department> Departments {
get;
set;
}
public List<Person> Persons {
get;
set;
}
public MainPage()
{
this.InitializeComponent();
Departments = new List<Department>
{
new Department {
DepartmentId = 1, DepartmentName = "R&D"
}
,
new Department {
DepartmentId = 2, DepartmentName = "Finance"
}
,
new Department {
DepartmentId = 3, DepartmentName = "IT"
}
};
Persons = new List<Person>
{
new Person
{
PersonId = 1, DepartmentId = 3, FirstName = "Ronald", LastName = "Rumple",
Position = "Network Administrator"
}
,
new Person
{
PersonId = 2, DepartmentId = 1, FirstName = "Brett", LastName = "Banner",
Position = "Software Developer"
}
,
new Person
{
PersonId = 3, DepartmentId = 2, FirstName = "Alice", LastName = "Anderson",
Position = "Accountant"
}
};
}
}
}