This is a migrated thread and some comments may be shown as answers.

Creating a CellStyleSelector as a reusable resource

4 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stu
Top achievements
Rank 1
Stu asked on 10 May 2012, 11:03 AM
Hello,

I am using a telerik:RadGridView with is bound to a collection.

In a column of have the following CellStyleSelector 

<telerik:GridViewDataColumn.CellStyleSelector>
                        <telerik:ConditionalStyleSelector>
                            <telerik:StyleRule Condition="Name= 'N/A'">
                                <telerik:StyleRule.Style>
                                    <Style TargetType="telerik:GridViewCell">
                                        <Setter Property="IsEnabled" Value="False"  />
                                    </Style>
                                </telerik:StyleRule.Style>
                            </telerik:StyleRule>
                        </telerik:ConditionalStyleSelector>
                    </telerik:GridViewDataColumn.CellStyleSelector>

This works perfectly for me. However I want this CellStyleSelector on every column expect the Name column.

Is it possible to add a CellStyleSelector as a XAML resource so I can reuse it.

e.g

<telerik:GridViewDataColumn CellStyleSelector="{StaticResource MySelector}" Name="colage" Width="50" Header="Age" DataMemberBinding="{Binding Age, Mode=TwoWay}" />

 I am aware I could create a style selector class but i would prefer to keep it all in the XAML



4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 May 2012, 11:22 AM
Hi,

 For such a scenario please check this help article.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stu
Top achievements
Rank 1
answered on 10 May 2012, 11:33 AM
The article was helpful but it does not explain how to do a pure XAML solution.

If possible I do not want to have to use a separate class.

Is it possible to add a cellStyleSelector as a pure XAML resource?
0
Accepted
Dimitrina
Telerik team
answered on 10 May 2012, 12:02 PM
Hello,

Please follow this online demo.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Stu
Top achievements
Rank 1
answered on 10 May 2012, 12:14 PM
Excellent.

That example was a great help.

All sorted now. Simple when you know how.

My solution show below.

    <UserControl.Resources>
        <telerik:ConditionalStyleSelector x:Key="CellEnabler">
            <telerik:StyleRule Condition="Name= 'N/A'">
                <telerik:StyleRule.Style>
                    <Style TargetType="telerik:GridViewCell">
                        <Setter Property="IsEnabled" Value="False"  />
                    </Style>
                </telerik:StyleRule.Style>
            </telerik:StyleRule>
        </telerik:ConditionalStyleSelector>
    </UserControl.Resources>
Tags
GridView
Asked by
Stu
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Stu
Top achievements
Rank 1
Share this question
or