[Record] DevExpress : GridControl

RedCock·2023년 1월 8일
0

Dev Tip

목록 보기
2/2
post-thumbnail

Logger 완성

//xaml
 <Window.Resources>
        <local:GridRowColorConverter x:Key="c"/>
 </Window.Resources>


<dxg:GridControl x:Name="gridLogView"
                 AutoGenerateColumns="AddNew" 
                 EnableSmartColumnsGeneration="True"
                 SelectionMode="None"                      
                 AllowInitiallyFocusedRow="True">
       <dxg:GridControl.View>
           <dxg:TableView AutoWidth="True" 
           				  AllowBestFit="True" 
                          BestFitMode="AllRows"
                          AllowEditing ="False"
						  ShowIndicator ="False" 
                          AllowScrollToFocusedRow="True"
                          EnableSelectedRowAppearance="False">
                    <dxg:TableView.RowStyle>
                        <Style TargetType="{x:Type dxg:RowControl}" BasedOn="{StaticResource {x:Type dxg:RowControl}}">
                           <Setter Property="Background" Value="{Binding Path=Row.Level, Converter={StaticResource c}}" />
                        </Style>
                    </dxg:TableView.RowStyle>
            </dxg:TableView>
       </dxg:GridControl.View>
</dxg:GridControl>

//C#

public class myColor
{
    /// <summary>
    /// On, True, Normal State Color
    /// </summary>
    public static readonly Brush On = (SolidColorBrush)new BrushConverter().ConvertFrom("#4AC99B");

    /// <summary>
    /// Off, False State Color
    /// </summary>
    public static readonly Brush Off = (SolidColorBrush)new BrushConverter().ConvertFrom("#778BFF");

    /// <summary>
    /// Warning State Color
    /// </summary>
    public static readonly Brush Warn = (SolidColorBrush)new BrushConverter().ConvertFrom("#FAE84F");

    /// <summary>
    /// Error State Color
    /// </summary>
    public static readonly Brush Error = (SolidColorBrush)new BrushConverter().ConvertFrom("#E95984");

    /// <summary>
    /// Fatal State Color
    /// </summary>
    public static readonly Brush Fatal = (SolidColorBrush)new BrushConverter().ConvertFrom("#92CAF4");
}

public class GridRowColorConverter : IValueConverter
{        
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
     {
         Brush b = null;

         switch (value.ToString())
         {
             case "INFO":
                 b = Brushes.White;
                 break;
             case "WARN":
                 b = myColor.Warn;
                 break;
             case "ERROR":
                 b = myColor.Error;
                 break;
             case "FATAL":
                 b = myColor.Fatal;
                 break;
             case "DEBUG":
                 b = myColor.On;
                 break;
             default:
                 b = Brushes.White;
                 break;
         }
        return b;
     }

     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
     {
         throw new NotImplementedException();
     }
}


gridLogView.ItemsSource = Logger.Instance.GetRecentLogList();
gridLogView.View.MoveLastRow();

profile
C#으로 개발하는 붉은 닭 띠 아들의 아빠

0개의 댓글