Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
XamDataGrid Custom Error Object to display Warnings and Errors
posted

Hello,

I have a custom Error Class that utilizes IErrorContainer and INotifyDataErrorInfo. It has a Severity enum Property that indicates whether it is an error or warning. Now Based on this property i want to change Cell appearance of XamDataGrid. I tried to use DataTemplate but couldn't different appearance. Is it possible in XamDataGrid? Do You have any example of such functionality?

        <DataTemplate x:Key="{x:Static igDP:DataPresenterBase.DataErrorContentTemplateKey}">
            <Border x:Name="Bd">
               <ContentPresenter
               ContentTemplate="{Binding Path=Content.Host.ContentTemplate, RelativeSource={x:Static RelativeSource.Self}}"
               DataContext="{Binding Path=Content.Host.DataContext, RelativeSource={x:Static RelativeSource.Self}}" />
            </Border>
            <DataTemplate.Triggers>
               <MultiDataTrigger>
                  <MultiDataTrigger.Conditions>
                     <Condition Binding="{Binding Path=ErrorContent.IsError}" Value="true" />
                  </MultiDataTrigger.Conditions>
                  <Setter TargetName="Bd" Property="Background" Value="{Red}" />
                  <Setter TargetName="Bd" Property="BorderBrush" Value="{Red}" />
                  <Setter TargetName="Bd" Property="BorderThickness" Value="1" />
                  <Setter TargetName="Bd" Property="CornerRadius" Value="0" />
                  <Setter TargetName="Bd" Property="ToolTip" Value="{Binding Path=Host.DataError}" />
               </MultiDataTrigger>
                <MultiDataTrigger>
                  <MultiDataTrigger.Conditions>
                     <Condition Binding="{Binding Path=ErrorContent.IsWarning}" Value="true" />
                  </MultiDataTrigger.Conditions>
                  <Setter TargetName="Bd" Property="Background" Value="{Yellow}" />
                  <Setter TargetName="Bd" Property="BorderBrush" Value="{Yellow}" />
                  <Setter TargetName="Bd" Property="BorderThickness" Value="1" />
                  <Setter TargetName="Bd" Property="CornerRadius" Value="0" />
                  <Setter TargetName="Bd" Property="ToolTip" Value="{Binding Path=Host.DataError}" />
               </MultiDataTrigger>
            </DataTemplate.Triggers>
         </DataTemplate>