How to change a color of a cell dynamically ? c# WPF


Keywords:c# 


Question: 

Good evening everyone, Excuse me for my bad english. I want to change the background color from negative or positive values but it should be more géneral in the future. Is it useless to give some link to look at because i've tryed some of them and i can't do them. Like NameToBrushConverter isn't compatible in wpf... Currently I have my datagrid into an application..

XAML code :

    <UserControl x:Name="AnUserControl" x:Class="WpfControls.MyDataGrid"
         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:WpfControls"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" MouseDoubleClick="UserControl_MouseDoubleClick" PreviewKeyDown="UserControl_PreviewKeyDown" MouseDown="UserControl_MouseClick" >
<UserControl.Resources>

    <Style x:Key="GridHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontSize" Value="12" />
    </Style>

    <Style x:Key="GridStyle" TargetType="{x:Type DataGrid}" >
        <Setter Property="AutoGenerateColumns" Value="False" />
        <Setter Property="IsReadOnly" Value="True" />
        <Setter Property="GridLinesVisibility" Value="None" />
        <Setter Property="CanUserAddRows" Value="False" />
        <Setter Property="CanUserDeleteRows" Value="False" />
        <Setter Property="CanUserResizeColumns" Value="True" />
        <Setter Property="CanUserResizeRows" Value="False" />
        <Setter Property="CanUserReorderColumns" Value="False" />
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource GridHeaderStyle}" />
    </Style>
</UserControl.Resources>
<DataGrid ItemsSource="{Binding Path=Records}" Name="xxx"
    Style="{StaticResource GridStyle}" Margin="0,-4,0,4" >
    <DataGrid.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Delete" Click="MenuItemDelete_Click" Name="Delete"  />
            <MenuItem Header="Add" Click="MenuItemAdd_click" />
        </ContextMenu>
    </DataGrid.ContextMenu>
</DataGrid>

How I should be able to change the color I looked in multiple Stackoverflow but my knowledge in wpf isn't good.. I want to use binding, because it would be for multiple using... I have an userControl and other exemple talk about window ressources and i currently don't know how to implement this into my code But in fact i'm missing some informations about binding and i think it's the cause I don't get it. If someone can get me some informations that could be amazing ! :) Thanks for answering have a nice day :)


1 Answer: 

this morning with a brain clean, I have resolved it I forget to chose to chose namespace and build it.. Hope it's helps for begginner