반응형
이전과 다르게 source data의 값을 활용하여, row color을 변경하였다.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | < Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" xmlns:local = "clr-namespace:WpfSample.DevTest" xmlns:dxlc = "http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dx = "http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:Serialization = "clr-namespace:DevExpress.Xpf.LayoutControl.Serialization;assembly=DevExpress.Xpf.LayoutControl.v17.2" xmlns:dxe = "http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxg = "http://schemas.devexpress.com/winfx/2008/xaml/grid" x:Class = "WpfSample.DevTest.Grid09RowColorDynamic" xmlns:dxgt = "http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys" mc:Ignorable = "d" d:DesignHeight = "700" d:DesignWidth = "1200" Title = "Grid01" > < Page.Resources > < ResourceDictionary > < local:GridRowColorConverter x:Key = "c" /> < Style x:Key = "RowColorStyle" TargetType = "{x:Type dxg:RowControl}" BasedOn = "{StaticResource {x:Type dxg:RowControl}}" > < Setter Property = "Background" Value = "{Binding Row.MaterialUnit, Converter={StaticResource c}}" /> </ Style > </ ResourceDictionary > </ Page.Resources > < StackPanel Margin = "0,10,10,10" > < dxlc:LayoutControl HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch" Orientation = "Vertical" > < dxlc:LayoutGroup Header = "Button" View = "GroupBox" HorizontalAlignment = "Stretch" > < dx:SimpleButton x:Name = "btnSearch" Content = "Search" HorizontalAlignment = "Left" Click = "Button_Click" /> </ dxlc:LayoutGroup > </ dxlc:LayoutControl > < dxlc:LayoutControl HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch" Orientation = "Vertical" > < dxlc:LayoutGroup Header = "Grid" View = "GroupBox" HorizontalAlignment = "Stretch" Height = "500" > < dxg:GridControl x:Name = "gcGrid" HorizontalAlignment = "Stretch" > < dxg:GridControl.View > < dxg:TableView AutoWidth = "True" AllowEditing = "True" RowStyle = "{StaticResource RowColorStyle}" > </ dxg:TableView > </ dxg:GridControl.View > < dxg:GridControl.Columns > < dxg:GridColumn FieldName = "CocktailNo" Header = "CocktailNoType1" Width = "110" /> < dxg:GridColumn FieldName = "CocktailNoType2" Header = "CocktailNoType2" Width = "110" /> < dxg:GridColumn FieldName = "CocktailMaterialNo" Header = "CocktailMaterialNo" Width = "100" /> < dxg:GridColumn FieldName = "MaterialCode" Header = "MaterialCode" Width = "100" /> < dxg:GridColumn FieldName = "MaterialName" Header = "MaterialName" Width = "100" /> < dxg:GridColumn FieldName = "MaterialQuantity" Header = "MaterialQuantity" Width = "100" /> < dxg:GridColumn FieldName = "MaterialUnit" Header = "MaterialUnit" Width = "100" /> < dxg:GridColumn FieldName = "Remark" Header = "Remark" Width = "100" /> < dxg:GridColumn FieldName = "UnitPrice" Header = "UnitPrice" Width = "100" /> < dxg:GridColumn FieldName = "CreateUser" Header = "CreateUser" Width = "100" /> < dxg:GridColumn FieldName = "CreateDate" Header = "CreateDate" Width = "100" /> < dxg:GridColumn FieldName = "UpdateUser" Header = "UpdateUser" Width = "100" /> < dxg:GridColumn FieldName = "UpdateDate" Header = "UpdateDate" Width = "100" /> </ dxg:GridControl.Columns > </ dxg:GridControl > </ dxlc:LayoutGroup > </ dxlc:LayoutControl > </ StackPanel > </ Page > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using BIZ.Common.Dac; namespace WpfSample.DevTest { /// <summary> /// Grid09RowColorDynamic.xaml에 대한 상호 작용 논리 /// </summary> public partial class Grid09RowColorDynamic : Page { public Grid09RowColorDynamic() { InitializeComponent(); GetBindGrid(); } private void GetBindGrid() { Dictionary< string , object > dic = new Dictionary< string , object >(); dic.Add( "param1" , 333); var data = ( new ADOConnect()).GetDataSet( "Kaishaku" , "Z_UP_COCKTAIL_MATERIAL_LIST" , dic); gcGrid.ItemsSource = data.Tables[0]; } private void Button_Click( object sender, RoutedEventArgs e) { GetBindGrid(); } } class GridRowColorConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Brush b = null ; switch (value.ToString()) { case "060601" : b = Brushes.Red; break ; case "060602" : b = Brushes.RoyalBlue; break ; case "060603" : b = Brushes.Yellow; break ; case "060604" : b = Brushes.Pink; break ; case "060605" : b = Brushes.Purple; break ; default : b = Brushes.White; break ; } return b; } public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } |
참고 URL
How to change the row color of the wpf grid programmatically
Change cell background color through code
supportcenter.devexpress.com/ticket/details/t554628/change-cell-background-color-through-code
WPF GridControl dynamic row color
supportcenter.devexpress.com/ticket/details/t326950/wpf-gridcontrol-dynamic-row-color/
The RowStyle target type is not supported in the grid's optimized mode.
반응형
'WPF - DevExpress' 카테고리의 다른 글
WPF & DevExpress GridControl Context Menu (4) | 2021.04.02 |
---|---|
WPF & DevExpress GridControl Move to next cell (6) | 2021.04.01 |
WPF & DevExpress GridControl RowColor #1 Basic (2) | 2021.03.30 |
WPF & DevExpress GridControl Cell Merge (2) | 2021.03.29 |
WPF & DevExpress GridControl Summary (3) | 2021.03.28 |
댓글