4

私はDataTemplate自分のWPFアプリケーション内で使用しているものを持っています -

<DataTemplate x:Key="mattersTemplate">
    <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0" Text="FileRef:"/>
            <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=FileRef}" />
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Description:"/>
            <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Description}"/>
            <TextBlock Grid.Row="2" Grid.Column="0" Text="Priority:"/>
            <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Priority}"/>
        </Grid>
    </Border>
</DataTemplate>

次に、(DocumentSetTemplateSelectorクラスで) 使用するテンプレートを定義します。

私がやりたい/知りたいことは; この上記のテンプレートを継承し、特定の属性を上書きできるようにする 4 つの他のテンプレートを作成します。

例 (このテンプレートは上記のクラスから継承されます) - 同じように見えます。

<DataTemplate x:Key="documentSet_Accounting">
    <ContentPresenter Content="{Binding mattersTemplate}" 
         ContentTemplate="{StaticResource mattersTemplate}">
    </ContentPresenter>
</DataTemplate>

この効果を得るために、(可能であれば)これにスタイルを付けたいと思います。

<DataTemplate x:Key="documentSet_Accounting">
    <ContentPresenter fontsize="20" Content="{Binding mattersTemplate}" 
         ContentTemplate="{StaticResource mattersTemplate}">
    </ContentPresenter>
</DataTemplate>

また

<DataTemplate x:Key="documentSet_Accounting">
    <ContentPresenter Style="AccountingStyle" Content="{Binding mattersTemplate}" 
         ContentTemplate="{StaticResource mattersTemplate}">
    </ContentPresenter>
</DataTemplate>
4

1 に答える 1

1

テンプレートの継承ではなく、テンプレート内でスタイルの継承を使用するのはどうですか?

<Style x:Key="mattersTemplateStyle">
    <Setter Property="TextBlock.Foreground" Value="Green"/>
</Style>
<Style x:Key="documentSet_AccountingStyle" BasedOn="{StaticResource mattersTemplateStyle}">
    <Setter Property="TextBlock.FontSize" Value="20"/>            
</Style>
<DataTemplate x:Key="mattersTemplate">
    <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5">
        <Grid Style="{StaticResource mattersTemplateStyle}">
            [...]
        </Grid>
    </Border>
</DataTemplate>
<DataTemplate x:Key="documentSet_Accounting">
    <Grid Style="{StaticResource documentSet_AccountingStyle}">
        <ContentPresenter Content="{Binding mattersTemplate}" ContentTemplate="{StaticResource mattersTemplate}"></ContentPresenter>
    </Grid>
</DataTemplate>
于 2012-11-28T12:37:34.393 に答える