Hello,
I'm tryng to set background color of row on my Xamgrid.
I make something like this :
<UserControl.Resources> <Style TargetType="{x:Type ig:CellControl}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Cell.Row.CommandeFournisseur.Numero}" Value="IC/140029"> <Setter Property="Background" Value="Red"/> </DataTrigger> </Style.Triggers> </Style> </UserControl.Resources>
But when the value is IC/140029 nothing append...
My xamgrid is like this :
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False" ColumnWidth="auto" FontSize="10" FontFamily="Calibri" Foreground="Black" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" RowHover="Row" RowHeight="20" Margin="5" ItemsSource="{Binding ListeAfterFiltre}">
ListeAfterFiltre is type of ObservableCollection<CommandeFournisseur>
thanks
Hello EASii IC,
Thank you for your post!
I have been looking into it and have created a small sample application for you. In it I have a simple XamGrid bind to a collection. In the collection I have a property UniqueID of type string, which has value - IC/140029.
I have used the style you have provided for the CellControl. Then I have changed the binding for the DataTrigger to
Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.UniqueID}".
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
It's ok with the color but i have a problem with column's height.
The column modif and pdf have a height problem.
My buttons are cut.
My table options are :
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False" ColumnWidth="auto" FontSize="10" FontFamily="Calibri" Foreground="Black" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" RowHover="Row" RowHeight="20" Margin="5" ItemsSource="{Binding ListeAfterFiltre}" >
My buttons are set like this :
<ig:UnboundColumn Key="Modif" HeaderText="Modif" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="50"><ig:UnboundColumn.ItemTemplate><DataTemplate><Button Style="{StaticResource EditButtonStyle}"Height="18" Command="{Binding DataContext.AfficherDetailCommand,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamGrid}}}" CommandParameter="{Binding RowData}"></Button></DataTemplate></ig:UnboundColumn.ItemTemplate></ig:UnboundColumn>
<ig:UnboundColumn Key="PDFFR" HeaderText="PDF FR" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsGroupable="False" IsFilterable="False" IsResizable="False"><ig:UnboundColumn.ItemTemplate><DataTemplate><Button Style="{StaticResource FlatIconeButton}" BorderBrush="White" Background="White" Name="FR"Command="{Binding DataContext.AfficherPDFCommandFR,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamGrid}}}" CommandParameter="{Binding RowData}"Height="20" Width="20"ToolTip="Afficher le PDF"><ContentControl Style="{StaticResource ERP_PDF_ContentControlStyle}" BorderBrush="Black"/></Button></DataTemplate></ig:UnboundColumn.ItemTemplate></ig:UnboundColumn>
Look at picture
I have been looking into your question.
From the code snippet, that you have provided I was able to see, that you are setting RowHeight property of XamGrid to 20. This way the entire row height would be 20. Around the content of the cells, there are margins and paddings, that can cause the content in the cells to be cut.
What I can suggest is to remove the RowHeight property. This way the height of the rows would be measured according to the content in the cells.
Please do not hesitate to let me know if you have any further questions on this matter.
The RowHeight 20 is good.
The problem appear when i add this :
<UserControl.Resources><Style TargetType="{x:Type ig:CellControl}"><Setter Property="Padding" Value="5 1"/><Style.Triggers><DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.TestAffaireNull}"Value="true"><Setter Property="Background" Value="Red"/></DataTrigger></Style.Triggers></Style></UserControl.Resources>
Margin or padding appear on each row without real reason
EDIT :
To resolve my probleme i have to add : <Setter Property="Padding" Value="5 1"/>
Pciture, i put the 2 case ; 2 lines with and 2 without
I have been looking into your question. I have updated the sample application I have sent in my previous post with the code snippet you have provided and I was not able to reproduce the behavior you have mentioned.
The binding errors that you are seeing are caused by the DataContext of the UnboundColumn. At first when the binding is created the DataContext of the UnboundField is not set. This is when the errors occur and the error message appears in the Output window. Then the DataContext(UnboundDataContext) is created for the UnboundField and the DataTrigger in the CellStyle is executed.
In release mode of the application these errors should have no influence on the performance of the application and there should not be a slowdown. In debug mode the errors are shown in the Output window and this is why the it might take time to write them in this window. In release mode on the other hand there is no Output window and the application would not take time for writing error messages. You can test this by setting the Solution Configuration to run as Release instead of Debug. One other way to test would be run the .exe file of the project.
So i will have 1 error for each row ?
If i have 10k row, i'll have 10k error.
The treatment is not slow down ?
I have some errors with this :
<ig:UnboundColumn Key="Modif" HeaderText="Modif" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="50" CellStyle="{StaticResource unbound}"><ig:UnboundColumn.ItemTemplate> <DataTemplate><Button Height="18"Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamGrid}}, Path=DataContext.Hello}" CommandParameter="{Binding RowData}"Content="Test"></Button></DataTemplate></ig:UnboundColumn.ItemTemplate></ig:UnboundColumn>
But i didn't get any error with this version :
<ig:UnboundColumn Key="Modif" HeaderText="Modif" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="50"><ig:UnboundColumn.ItemTemplate> <ig:UnboundColumn.CellStyle><Style TargetType="{x:Type ig:CellControl}"><Setter Property="Padding" Value="5 1"/><Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.RowData.UniqueID}" Value="IC/140029"><Setter Property="Background" Value="Red"/></DataTrigger>
</Style.Triggers></Style></ig:UnboundColumn.CellStyle><DataTemplate><Button Height="18"Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamGrid}}, Path=DataContext.Hello}" CommandParameter="{Binding RowData}"Content="Test"></Button></DataTemplate></ig:UnboundColumn.ItemTemplate></ig:UnboundColumn>
I didn't understand why...
When the solution builds for the first time the DataContext for the UnboundColumn is not set. Then the DataContext for this column is set and the binding for the CellContol is created.
When the application starts the binding is already created and the Background property is being set.
When i use your sample i have some error in output :
System.Windows.Data Error: 40 : BindingExpression path error: 'RowData' property not found on 'object' ''Worker' (HashCode=46243781)'. BindingExpression:Path=DataContext.RowData.UniqueID; DataItem='CellControl' (Name=''); target element is 'CellControl' (Name=''); target property is 'NoTarget' (type 'Object')
Thank you for the provided sample application. I was able to reproduce the issue. What I can suggest is to create an additional style for the UnboundColumns. In this style you can set the binding to the DataContext.RowData. UniqueID.
I have modified the sample application for you. Please find it attached and feel free to let me know if you have any further questions on this matter.