3

ComboBox などのコントロールを (再) テンプレート化したいと考えています。

XAML:

<ComboBox Style="{StaticResource MyComboBoxStyle}" ... >
    <!-- ... -->
</ComboBox>

ControlTemplate に Button が必要です。

リソース辞書:

<Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <Grid>
                    <!-- ... -->

                    <Button Command="{TemplateBinding Tag}" CommandParameter="{Binding ???}" />

                    <!-- ... -->
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

CommandParameterしかし、テンプレートを適用したコントロール (この例では ComboBox)に設定したいと思います。

どうすればこれを解決できますか?

4

1 に答える 1

10

わかりました、私は正しい解決策を見つけました。

バインディングをに設定しましたBinding RelativeSource={RelativeSource TemplatedParent}

<Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <Grid>
                    <!-- ... -->

                    <Button Command="{TemplateBinding Tag}" CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}" />

                    <!-- ... -->
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2012-11-29T12:09:18.810 に答える