Hi,
As per my requirement, I need to load the rows and columns dynamically.
So I used 2 classes one is to get the Column name and type ; and another class to get row information.
I took data table and created the Columns as ColumnInfo class and also updated rows info[From RowsInfo class].
And depends upon Type info from ColumnInfo class(like,TextBox,ComboBox,TextBlock) I created different styles in Xaml respectively.
Later I binded to DataTable to XamDatagrid.
I used below style for one of Field through code behind
<Style x:Key="InCellStyle" TargetType="{x:Type igDP:CellValuePresenter}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}" > <Border CornerRadius="2" Name="MainBorder" BorderThickness="2" BorderBrush="{Path = BorderColor}"> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="TextBlock" Text="{Binding Path= Value, RelativeResource={RelativeResource Mode=TemplatedParent} }" /> </StackPanel></Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
Once i applied above style, I am able to see the Data in cell but not border Color.
I observered following error in output window of Visual studio
>>
System.Windows.Data Warning: 40 : BindingExpression path error: 'BorderColor' property not found on 'object' ''DataRecord' (HashCode=5604335)'. BindingExpression:Path=BorderColor; DataItem='DataRecord' (HashCode=5604335); target element is 'Border' (Name=''); target property is 'BorderBrush' (type 'Brush')
<<
Could you please let me , how to resolve the above issue and get the border for specific cell.
Thank you,
Chandra
Could you please help me to resolve the issue...
Thanks,
Hello Chandra,
This binding error is expected since the DataContext of the Border is DataRecord and it doesn't have a BorderColor Property, I can suggest you chnage the Binding depending on to which item the BorderColor Property belongs.
Hope this helps you.
Since I am not completely sure how your data is organized, I cannot say what the Binding should be, so could you please send an isolated sample project with a similar data to your original one, so I can investigate it further for you.
Looking forward for your reply.
Hi Stefan,
Thanks for your reply.
I am attaching my solution, which is currently I am working on it.
Thanks in advance..
Waiting for your reply...
Regards,
Have you got chance to look into the solution, which i have attached in my earlier post.
Could you please help me to achieve my requirement.
I believe Yanko has already answer your question here:
http://ko.infragistics.com/community/forums/p/78237/396727.aspx#396727
I saw Yanko's reply and in her reply
if ((value as DataRecord).Cells[0].Value.ToString() == "CV002" && (value as DataRecord).Cells[0].Record.Index ==1)
{
return Brushes.Orange;
}
else if ((value as DataRecord).Cells[0].Value.ToString() == "CV002" && (value as DataRecord).Cells[0].Record.Index == 2)
return Brushes.Pink;
In this case, CV002 and Index values are static.
But in my case, RowData is dynamic.So i cant apply the above condition to apply borderColor.
I need to apply BorderColor and Image depends upon CellData.ErrorType.Warning..
Otherthan Yanko's approach..is there any other approach ?
You can use the following Style:
<Style x:Key="TextBlockCellStyle" TargetType="{x:Type igDP:CellValuePresenter}" > <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding RelativeSource={RelativeSource Self},Path=Value}" Value="CV002"/> <Condition Binding="{Binding RelativeSource={RelativeSource Self},Path=Record.DataItem.ErrorType}" Value="Warning"/> </MultiDataTrigger.Conditions> <MultiDataTrigger.Setters> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Border CornerRadius="2" Name="MainBorder" BorderThickness="2" BorderBrush="{Binding Path=DataItem[BorderColor]}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path= Value, RelativeSource={RelativeSource Mode=TemplatedParent}}" /> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </MultiDataTrigger.Setters> </MultiDataTrigger> </Style.Triggers> </Style>
which uses a MultiDataTrigger and it will color the Cell if its value is "CV002" and if the DataItem's ErrorType is "Warning".
As per your suggestions,
I added new Column to DataTable and hide the field and added to fieldLayout as below
dt.Columns.Add("ErrorType"); Field field1 = new Field("ErrorType"); field1.Visibility = Visibility.Hidden;
fieldLayout.Fields.Add(field1);
And I applied below style to CellValuePresenter
<Style x:Key="TextBlockCellStyle" TargetType="{x:Type igDP:CellValuePresenter}" > <!--<Setter Property="Background" Value="red"/> <Setter Property="Value" Value="{Binding Path=DataItem[BorderColor],Converter={StaticResource testconv}}"/>--> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Border CornerRadius="2" Name="MainBorder" BorderThickness="2" > <StackPanel Orientation="Horizontal"> <TextBlock x:Name="TextBlock" Text="{Binding Path=Value, RelativeSource={RelativeSource Mode=TemplatedParent}}" /> <Image x:Name="Image" Source="{Binding Converter={StaticResource testImage}}" /> </StackPanel> </Border> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding Path=DataItem.ErrorType}" Value="Warning">
<Setter TargetName="MainBorder" Property="BorderBrush" Value="Red" />
</DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
In this case, its not applicable for specific cell, Whether I need to add any extra condition to this?
I am attaching the screenshot for your reference.
Please help me out this issue
Thanks for your reply and suggestion..
Could you please provide me the sample solution, which which can achieve the above requirement.
Thanks in advance.
I have been looking into your data and I noticed that the XamDataGrid’s DataSource is a DataTable, which is created based on the Rows collection items, where the ErrorType Property belongs to, so my suggestions is to add one more column into the DataTable with this information (ErrorType) and if you don’t want to show it, you can define a FieldLayout for the XamDataGrid and hide that Field. This way you can easily make a MultiTrigger to show red border when the value is CV002 and the ErrorType is Warning.