I have a CellTemplate with DataTemplate.Triggers defined:
<Window.Resources>
<DataTemplate x:Key="ActiveGraphic">
<StackPanel>
<Control x:Name="icon" Template="{StaticResource addImage}" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Enabled}" Value="True">
<Setter TargetName="icon" Property="Template" Value="{StaticResource addImage}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Enabled}" Value="False">
<Setter TargetName="icon" Property="Template" Value="{StaticResource deleteImage}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
and GridViewDataColumn:
<telerik:GridViewDataColumn Header="Activated" DataMemberBinding="{Binding Path=Enabled}" CellTemplate="{StaticResource ActiveGraphic}" />
DataTemplate.Traggers doesn't fire and Template property never changes from default.
16 Answers, 1 is accepted
It seems you have hit a known issue in RadGridVIew. The problem is due to the specific way RadGridVIew loads the cell template. We are already working on the fix. I believe this will take some time as we do not want to introduce major breaking changes. Therefore I am offering you the following workaround :
Instead of using the CellTemplate property , please use the CellStyle property of the column. Within the cell style set the ContentTemplate property. This should force the cell to apply the template the standard way and triggers would be fine ( tested ).
XAML would be something like :
<
Style
TargetType
=
"telerik:GridViewCell"
x:Key
=
"MyCellStyle"
>
<
Setter
Property
=
"ContentTemplate"
>
<
Setter.Value
>
<
DataTemplate
>
... <
DataTemplate.Triggers
>
...
</
DataTemplate.Triggers
>
</
DataTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
telerik:RadGridView
x:Name
=
"RadGridView1"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumnCellStyle
=
"{StaticResource MyCellStyle}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I have a trigger inside data template that is not working.
The issue is still present, however you can use the workaround provided by my colleague.
Instead of using the CellTemplate property , please use the CellStyle property of the column. Within the cell style set the ContentTemplate property. This should force the cell to apply the template the standard way and triggers would be fine ( tested ).
You can track the state of the issue and vote for its resolution here.
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I guess a better way to do it.
How else can I do this? I need to designate a style with a DataTrigger for dynamically changing the cell style.
This does not work. How else can I do this?
Style style = new Style(typeof(TextBlock));
style.Setters.Add(new Setter(TextBlock.ForegroundProperty, Brushes.Green));
DataTrigger dataTrigger = new DataTrigger() { Binding = new Binding("DateNeededBy") { Converter = new PastDateToBooleanConverter() }, Value = true };
dataTrigger.Setters.Add(new Setter(TextBlock.ForegroundProperty, Brushes.Red));
style.Triggers.Add(dataTrigger);
myColumn.CellTemplate.VisualTree.SetValue(TextBlock.StyleProperty, style);
However, this works, but then I have no Style or Triggers:
myColumn.CellTemplate.VisualTree.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
The idea is to use the GridViewColumn.CellStyle property.
Let me know if you encounter any problem with the implementation!
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
<
telerik:RadGridView
x:Name
=
"RadGridView1"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumnCellStyle
=
"{StaticResource MyCellStyle}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Seems wrong. If it is wrong, could you provide the correct example?
Thank you
Here is the correct syntax:
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Property}"
>
<
telerik:GridViewDataColumn.CellStyle
>
<
Style
/>
</
telerik:GridViewDataColumn.CellStyle
>
</
telerik:GridViewDataColumn
>
Hope it helps! Kind regards,
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
ummm... I guess what I am looking for, is way to set the default look of cells in a RadGridView so I don't have to set it on each column. However I dont know if it means styling cells or rows or columns or the RadGridView itself or ...
The behaviour I have now is this: when I resize columns (i.e make them narrow), the textual data in the cells will wrap and the row will grow to always show all that text. This means that I get rows that are extremely stretched to show the text.
The format I want is this: when I resize columns (to make them narrow), the text will wrap ... to a point, but if there are more than, say, 3 lines needed to show the text, the cell should then get horizontal/vertical scroll bars so the user can access all the text if need be. That way the rows stay as reasonably compact.
I suspect there are several ways of accomplishing this.
1) if there is a cell styling way of doing this, I would like to see it so I have a simple example of styling cells
2) If there is a row/column formatting way of doing it, I would like to see that too, so I can learn about "styling" rows/colums
Thoughts?
We have various examples of how you can customize the Styles/Templates of the Cells and Rows.
Here are some of them:
http://demos.telerik.com/silverlight/#GridView/Selectors/DataTemplateSelectors/CellTemplateSelector
http://demos.telerik.com/silverlight/#GridView/CustomRowLayout
http://demos.telerik.com/silverlight/#GridView/Selectors/StyleSelectors/RowStyleSelector
You can find the same demos for WPF in your local copy of our Examples.
Hope this helps!
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Ummm... The examples have value, but I am not sure how they can be used to solve my need.
I am looking for a way to change the default format of most cells in most of my RadGridView (there are some exceptions but I want to define the default look of cells). The examples shown bind to specific data or set the style based on a choice and dont solve the general case.
I am looking to define some thing that when I call:
<telerik:GridViewDataColumn Header="Product ID" DataMemberBinding="{Binding ProductID}" Width="60" />
<telerik:GridViewDataColumn Header="In Stock" DataMemberBinding="{Binding InStock}" Width="60" />
<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" Width="60" />
<telerik:GridViewDataColumn ......
in each case the text (i.e ProductID, InStock, Name, etc ) should presented in a TextBox that has a MaxLines or MaxHeight and shows scroll bars if needed (and other attributes that I might want to be common)
I am hoping I am expressing my need correctly
Thank you for you help
I define a DataTemplate for the grid view cell. The trouble I had was accessing the text data within the template. Finally I see that I can use GridViewCell Value.
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewCell}},Path=Value}"
(not pretty but it works)
Now I can use
<telerik:GridViewDataColumn Header = "Name" DataMemberBinding="Name" CellTemplate={StaticResource TextCellTemplate} />
This also relates to http://www.telerik.com/community/forums/wpf/gridview/regarding-gridviewcell-value-binding.aspx
Thank you
Could you please provide an update on the status of this issue? Thanks, Tony.
I am afraid that we had to close this issue, as we did not find an appropriate fix after researching it extensively. I am posting a comment by the colleague, who worked on the issue:
"Indeed, it has been awhile, but we tried to find a solution that will not break the current functionality or introduce performance problems. With WPF DataGrid DataTemplate used as CellTemplate is set directly as ContentTemplate to the cell and all triggers are directly transferred.
However, with RadGridView the content of the cell is set from template.LoadContent() method and is returned from the CreateCellElement method of the column.
One possible scenario for a fix is to change that behavior and apply directly the template as WPF DataGrid does. However, this is a huge breaking change with CreateCellElement method is widely used. The second approach is to leave the code as it is right now, return the element from LoadContent method of DataTemplate and set the ContentTemplate property of the cell to that DataTemplate. This will cause the content to be loaded twice. Which will degrade the performance.
So, as it turns out the solution is either to introduce breaking change, or degrade the performance. Both of them are against our believes and efforts to improve the controls.
Our suggestion is to use the workaround by setting triggers directly to the style. We do hope you understand our concerns."
Please, let us know if the suggested workaround works for you.
Regards,
Ivan Ivanov
Telerik
Hello!
I indeed can set ContentTemplate in CellStyle, but how do I use triggers in CellEditTemplate?
The approach should be the same - set the triggers to the style of the editing element. For example, if the editing element is TextBox:
<
Style
TargetType
=
"TextBox"
>
<
Style.Triggers
>
<
DataTrigger
Binding
=
"{Binding Path=IsChampion}"
Value
=
"True"
>
<
Setter
Property
=
"Background"
Value
=
"BlueViolet"
/>
</
DataTrigger
>
</
Style.Triggers
>
</
Style
>
Regards,
Maya
Telerik