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

Style does work inside DataTemplate

1 Answer 406 Views
GridView
This is a migrated thread and some comments may be shown as answers.
YYZRichard
Top achievements
Rank 2
YYZRichard asked on 28 Jan 2011, 04:41 AM
I'm trying to apply a style to an image inside a DataTemplate, but it doesn't seem to work. It works fine if the style is applied to an image outside the RadGridView.

Here's the xaml for the RadGridView, and I'm refering to Style="{StaticResource ico16}" in the code below:

<telerik:RadGridView Grid.Column="1"
                     Grid.Row="1"
                     AutoGenerateColumns="False"
                     DataContext="{Binding Grid}"
                     ItemsSource="{Binding XPath=/Collection}"
                     RowIndicatorVisibility="Collapsed"
                     ShowGroupPanel="False"
                     GridLinesVisibility="Horizontal"
                     telerik:StyleManager.Theme="Windows7">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Width="*">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" >
                        <Image Source="{Binding XPath=@Icon}" ToolTip="{Binding XPath=@Tooltip}" Style="{StaticResource ico16}" />
                        <TextBlock Text="{Binding XPath=@Key}" Foreground="Black" />
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

On the same VIEW where the code above resides, there's a link to a resource dictionary where the style is defined:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MyAssemblyNameHere;component/Resources/MyResourceDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

The style is defined on a ResourceDictionary as follows:

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  
    <Style x:Key="ico16" TargetType="Image">
        <Setter Property="Margin" Value="0 0 5 0" />
        <Setter Property="Width" Value="16"/>
        <Setter Property="Height" Value="16"/>
        <Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality"/>
        <Setter Property="Stretch" Value="UniformToFill"/>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
    </Style>
  
</ResourceDictionary>

Any help is greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
YYZRichard
Top achievements
Rank 2
answered on 28 Jan 2011, 05:06 AM
I just realized the issue is not related to the STYLE.
I set all the properties for the image instead of using STYLE, and found out that only the property below is not working as expected inside a DataTemplate. It works fine when placed outside the RadGridView.

RenderOptions.BitmapScalingMode="HighQuality"

Tags
GridView
Asked by
YYZRichard
Top achievements
Rank 2
Answers by
YYZRichard
Top achievements
Rank 2
Share this question
or