0

ウィンドウ リソースとしてを作成したいのですがStyle、そのスタイルは、割り当てられたコントロールのプロパティにバインドする必要があります。以下はその簡単な例です。

ボタンのスタイルを作成し、Backgroundその割り当てられたボタン コントロール タグ プロパティを使用して色を適用します。

<Window.Resources>
    <Style x:Key="TestingStyle" TargetType="Button">
        <Setter Property="Background" Value="{Binding Tag}" />
    </Style>
</Window.Resources>

に を追加するButtonと、このスタイルはその色を の背景に適用する必要がありColorます。これは可能ですか?TagButton

編集

以下は実際の XMAL コードです。

<Style x:Key="SeriesStyle" TargetType="Chart:ChartSeries">
    <Setter Property="StrokeThickness" Value="2"/>
    <Setter Property="PointMarkerTemplate">
        <Setter.Value>
            <ControlTemplate>
                <Ellipse Width="7" Height="7" Fill="Lavender" Stroke="{Binding RelativeSource={RelativeSource Self}, Path=SeriesColor}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

2 に答える 2

2

はい、それは可能ですが、オブジェクトを色に変換するコンバーターを作成するだけでなく、RelativeSource にバインドする必要があります。これは、Tag が色ではなくオブジェクトを格納するためです。相対ソース。

 <Setter Property="Background" Value="{Binding Path=Tag, RelativeSource={RelativeSource Self}}}" />

編集:
Series Color が ChartSeries のプロパティであると仮定すると、次のように使用されます。

{Binding Path=SeriesColor, RelativeSource={RelativeSource AncestorType={x:Type Chart:ChartSeries}}}
于 2013-05-07T22:20:16.967 に答える