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

Binding and Style

3 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris Greening
Top achievements
Rank 1
Chris Greening asked on 14 May 2010, 03:33 PM

Does anyone have an exampe of how to bind any of the Style properties?

I've tried the following but it ignores the style but does pick up the TextBrushStyle and my header is black text on a black background:

XAML
<my:GridViewDataColumn IsGroupable="True" IsFilterable="True" IsReadOnly="True" Header="Reference No." DataMemberBinding="{Binding Path=ReferenceNo}" HeaderCellStyle="{Binding GrdCasesHeaderCellStyle}"

Code
Style _grdCasesHeaderCellStyle;

public Style GrdCasesHeaderCellStyle
{
get { return _grdCasesHeaderCellStyle; }
set 
{
_grdCasesHeaderCellStyle = value;
NotifyPropertyChanged("GrdCasesHeaderCellStyle");
}
}

GrdCasesHeaderCellStyle = Application.Current.Resources["GridViewHeaderCellStyle"] as Style;

Resources
<SolidColorBrush x:Key="TextBrush" Color="{StaticResource BlackColor}" />

<Style x:Key="GridViewHeaderCellStyle" TargetType="Telerik_Windows_Controls_GridView:GridViewHeaderCell">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="White"/>
</Style>

3 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 14 May 2010, 03:55 PM
Hello Chris Greening,

 You don't need to bind your style properties. You should assign static resources to them. In your case:

HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}"

Binding like you have done is completely unnecessary.

I hope this helps.

Regards,
Yavor Georgiev
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.
0
Chris Greening
Top achievements
Rank 1
answered on 14 May 2010, 04:00 PM

Yes that works well but I want to be able to define the style of my application in one location, hence the use of Application.Current.Resources"GridViewHeaderCellStyle"], as we will have lots of different XAML's using grids

Is this possible or not?

0
Yavor Georgiev
Telerik team
answered on 17 May 2010, 12:15 PM
Hi Chris Greening,

The StaticResource and DynamicResource markup extensions look for definitions not only in the current element's Resources, but their parents, as well. So if you define a resource in your Appl.xaml, you can access it from anywhere in your Silverlight application. Same goes for imported ResourceDictionaries and DynamicResource. In fact, this is the technique Expression Blend uses to store templates and other resources in auxiliary XAML files and access them.

Best wishes,
Yavor Georgiev
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.
Tags
GridView
Asked by
Chris Greening
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Chris Greening
Top achievements
Rank 1
Share this question
or