views:

856

answers:

1

I am trying to put as much properties of a Path element into a Style, this works out ok, as longs as I don't add Data to the Style setters:

<UserControl x:Class="Demo.Controls.SilverlightControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <Style x:Name="PathStyle" TargetType="Path">
                <Setter Property="Data" Value="0,0 L1,0"></Setter>
                <Setter Property="Stroke" Value="Blue"></Setter>     
                <Setter Property="Stretch" Value="Fill"></Setter>
            </Style>

        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Path Grid.Row="0"
               Height="7"               
               Data="M0,0 L1,0"
               Stretch="Fill"
               Stroke="Black"/>
        <Path Grid.Row="1"
               Height="7"               
               Style="{StaticResource PathStyle}"/>
    </Grid>
</UserControl>

If you open this example, you'll see that the first path gives no problems, but the second one results in an AG_E_UKNOWN_ERROR in Visual Studio 2008.

Is it possible to define the Data of a Path in a Style?

+2  A: 

This should work

<Style x:Name="PathStyle" TargetType="Path">
                <Setter Property="Data" Value="M0,0 L1,0"></Setter>
                <Setter Property="Stroke" Value="Blue"></Setter>
                <Setter Property="Stretch" Value="Fill"></Setter>
            </Style>