Hi,
As per my requirement , I need to apply specific style for Cell.
Once you applied style, Cell will have Value, Border Color and image depends on the collection set it in binding.
To achieve above requirement..which Targettype need to be used to apply Style?
Thanks,
Chandra
Hi Chandra,
You can try this code in the ‘Loaded’ event of the XamDataGrid :
Style cellChangedStyle = new Style(typeof(CellValuePresenter));
cellChangedStyle.Setters.Add(new Setter(CellValuePresenter.BackgroundProperty, Brushes.Red));
cellChangedStyle.Setters.Add(new Setter(CellValuePresenter.ForegroundProperty, Brushes.Yellow));
cellChangedStyle.Setters.Add(new Setter(CellValuePresenter.BorderBrushProperty, Brushes.Green));
cellChangedStyle.Setters.Add(new Setter(CellValuePresenter.BorderHoverBrushProperty, Brushes.Green));
cellChangedStyle.Setters.Add(new Setter(CellValuePresenter.BorderSelectedBrushProperty, Brushes.Green));
CellValuePresenter.FromCell((this.xamDataGrid1.Records[0] as DataRecord).Cells[0]).Style = cellChangedStyle;
The first cell will apply the style.
Hi Yanko,
Could you please provide me some sample example...so that i can use it as reference.
Thank you,
Thank you for your feedback. The easiest way to apply ‘CellValuePresenter’ style for specific cell of the XamDataGrid is by code. For example, in the ‘Loaded’ event :
private void xamDataGrid1_Loaded(object sender, RoutedEventArgs e)
{
Style cellChangedStyle = this.LayoutRoot.Resources["cellValuePres"] as Style;
}
Also you can set the desired properties in the style through code.
Let me know, if you need any further assistance on this matter.
I am using XamDataGrid Control. So I created style for CellvaluePresenter .
>>
<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="{Binding BorderColor,FallbackValue=Red}"> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="TextBlock" Text="{Binding Value, FallbackValue=99,RelativeSource={RelativeSource Mode=TemplatedParent}}" /> <Image x:Name="Image1" Source="{Binding}"/> <!--<Image Width="Auto" Source="pack://application:,,,/WpfCustomControlLibrary7;component/Images/WarningImg.png" HorizontalAlignment="Right" x:Name="Image1" />--> </StackPanel> </Border> <!--</Border>--> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CustomControl1}},Path=EnableWarningFlag}" Value="True"> <Setter Property="Source" TargetName="Image1" Value="pack://application:,,,/WpfCustomControlLibrary7;component/Images/WarningImg.png"></Setter> <Setter Property="BorderBrush" TargetName="MainBorder" Value="Blue"></Setter> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
<<
I want to apply CellvaluePresenter Style for specific cell.
How Can I achieve this?
If I apply above style, I need to get BorderColor ,Value and image in the Cell depends on specific properties
Could you please help me in this.
Hello Chandra,
Thank you for post. If you are working with XamGrid, you need to create a style with target element “CellControl” :
http://help.infragistics.com/Help/NetAdvantage/WPF/2012.2/CLR4.0/html/Designers_Guide_Styling_Points_for_xamGrid.html
If working with the XamDataGrid, you need style for “CellValuePresenter” :
http://help.infragistics.com/Help/NetAdvantage/WPF/2012.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v12.1~Infragistics.Windows.DataPresenter.CellValuePresenter.html
Let me know, if you need any further assistance on this matter