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

Apply Style to Specific GridView

5 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 17 Dec 2013, 11:12 PM
I have the following style defined in my WPF;

<Style TargetType="{x:Type telerik:GridViewRow}">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Path=IsActive}" Value="False" />
                <Condition Binding="{Binding Path=InPlan}" Value="True" />
            </MultiDataTrigger.Conditions>
 
            <Setter Property="Background" Value="AntiqueWhite" />
            <Setter Property="Foreground" Value="Red" />
        </MultiDataTrigger>
    </Style.Triggers>
</Style>

My problem is that this style is only applicable to one grid on the form, consequently I am getting binding errors on each of the other grids when the form loads.  How do I apply this style to the appropriate grid?

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Dec 2013, 09:28 AM
Hi,

You can specify a x:Key for the Style and then set is as a RowStyle of the RadGridView it is applicable for.

Let me know how this works for you.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Raymond
Top achievements
Rank 1
answered on 18 Dec 2013, 08:56 PM
Thanks Didie but WPF styling is not my strong point - after adding the key to the style I couldn't find where in the Gridview to set the GridViewRow style to use it;

<Style x:Key="InactiveGridRecord" TargetType="{x:Type telerik:GridViewRow}">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Path=IsActive}" Value="False" />
                <Condition Binding="{Binding Path=InPlan}" Value="True" />
            </MultiDataTrigger.Conditions>
     </Style.Triggers>
</Style>

<telerik:RadGridView Name="gvRigList"
    Grid.Row="4"
    Grid.Column="0"
    Grid.ColumnSpan="4"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Margin="5"
    telerik:StyleManager.Theme="Office_Blue"
    AutoGenerateColumns="False"
    ShowGroupPanel="True"
    RowIndicatorVisibility="Collapsed"
    IsSynchronizedWithCurrentItem="True"
    ItemsSource="{Binding}"
    DataLoadMode="Synchronous"
    ToolTip="Select a template record to edit"
    UseLayoutRounding="True"
    ShowColumnFooters="True"
    ShowGroupFooters="True"
    CanUserDeleteRows="False"
    CanUserInsertRows="False">
 
    <telerik:RadGridView.Resources>
        <Style TargetType="ListBox">
            <Setter Property="MaxHeight" Value="400" />
        </Style>
    </telerik:RadGridView.Resources>
 
    <telerik:RadGridView.GroupDescriptors>
        <telerik:GroupDescriptor Member="RigClass" SortDirection="Ascending" />
        <telerik:GroupDescriptor Member="RigType" SortDirection="Ascending" />
    </telerik:RadGridView.GroupDescriptors>
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewCheckBoxColumn Header="Active" UniqueName="IsActive" IsReadOnly="True" Width="auto" TextAlignment="Center" />
        <telerik:GridViewCheckBoxColumn Header="In Plan" UniqueName="InPlan" IsReadOnly="True" Width="auto" TextAlignment="Center" />
        <telerik:GridViewDataColumn Header="Rig Class" UniqueName="RigClass" IsReadOnly="True" Width="auto" />
        <telerik:GridViewDataColumn Header="Rig Type" UniqueName="RigType" IsReadOnly="True" Width="auto" />
        <telerik:GridViewDataColumn Header="Rig Name" UniqueName="RigName" IsReadOnly="True" Width="auto" />
        <telerik:GridViewDataColumn Header="Current Status" UniqueName="ContractStatus" IsReadOnly="True" Width="auto" />
 
        <telerik:GridViewDataColumn Header="From" UniqueName="FromDate" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=FromDate, Converter={StaticResource DateToText}, ConverterParameter=MediumDate}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Spud" UniqueName="SpudDate" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=SpudDate, Converter={StaticResource DateToText}, ConverterParameter=MediumDate}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="To" UniqueName="ToDate" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=ToDate, Converter={StaticResource DateToText}, ConverterParameter=MediumDate}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Confirmed RY" UniqueName="RigYearsConfirmed" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=RigYearsConfirmed, Converter={StaticResource NumberToFixedString}, ConverterParameter=0.00}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
 
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction ResultFormatString="{} {0:0.00}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Proposed RY" UniqueName="RigYearsProposed" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=RigYearsProposed, Converter={StaticResource NumberToFixedString}, ConverterParameter=0.00}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
 
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction ResultFormatString="{} {0:0.00}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Total RY" UniqueName="RigYearsTotal" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=RigYearsTotal, Converter={StaticResource NumberToFixedString}, ConverterParameter=0.00}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
 
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction ResultFormatString="{} {0:0.00}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Remaining RY" UniqueName="RigYearsRemaining" IsReadOnly="True" Width="auto">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=RigYearsRemaining, Converter={StaticResource NumberToFixedString}, ConverterParameter=0.00}" HorizontalAlignment="Right" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
 
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction ResultFormatString="{} {0:0.00}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

Could you show in the code above where to markup the style.

Thanks.
0
Raymond
Top achievements
Rank 1
answered on 18 Dec 2013, 09:11 PM
I tried using;

<telerik:RadGridView Name="gvRigList"
    Grid.Row="4"
    Grid.Column="0"
    Grid.ColumnSpan="4"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Margin="5"
    telerik:StyleManager.Theme="Office_Blue"
    AutoGenerateColumns="False"
    ShowGroupPanel="True"
    RowIndicatorVisibility="Collapsed"
    IsSynchronizedWithCurrentItem="True"
    ItemsSource="{Binding}"
    DataLoadMode="Synchronous"
    ToolTip="Select a template record to edit"
    UseLayoutRounding="True"
    ShowColumnFooters="True"
    ShowGroupFooters="True"
    CanUserDeleteRows="False"
    CanUserInsertRows="False">
 
    <telerik:RadGridView.RowStyle>
        <Style x:Name="InactiveGridRecord" />
    </telerik:RadGridView.RowStyle>
     
.
.
.
</telerik:RadGridView>

But this stopped the style from being applied to any of the rows?
1
Accepted
Dimitrina
Telerik team
answered on 19 Dec 2013, 09:35 AM
Hello,

You can explicitly apply the Style using one of the following two approaches:
1. 
<telerik:RadGridView ...
      RowStyle="{StaticResource InactiveGridRecord}">
2. 
<telerik:RadGridView.RowStyle>
    <Style TargetType="{x:Type telerik:GridViewRow}">
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Path=IsActive}" Value="False" />
                    <Condition Binding="{Binding Path=InPlan}" Value="True" />
                </MultiDataTrigger.Conditions>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</telerik:RadGridView.RowStyle>


Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Raymond
Top achievements
Rank 1
answered on 19 Dec 2013, 08:40 PM
Thanks Didie - worked a treat...
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or