独自のSelectionBoxItemTemplate添付プロパティを作成し、コンボボックスの新しいスタイル/コントロールテンプレートを定義して、選択ボックス領域のコンテンツプレゼンターでそのテンプレートを使用することで、これを行うことができます。 、ComboBoxコントロールのテンプレートを更新するには
public class ComboBoxExt
{
public static DataTemplate GetSelectionBoxItemTemplate(DependencyObject obj)
{
return (DataTemplate) obj.GetValue(SelectionBoxItemTemplateProperty);
}
public static void SetSelectionBoxItemTemplate(DependencyObject obj, DataTemplate value)
{
obj.SetValue(SelectionBoxItemTemplateProperty, value);
}
public static readonly DependencyProperty SelectionBoxItemTemplateProperty =
DependencyProperty.RegisterAttached("SelectionBoxItemTemplate", typeof (DataTemplate), typeof (ComboBoxExt),
new PropertyMetadata(null));
}
ContentPresenterBorder
と呼ばれる1内部ContentPresenter
という名前の要素を探します(コンボボックスhereのデフォルトスタイルを見つけることができます):
はここで、適切な添付プロパティです。 ContentPresenterの名前を削除する必要があります。そうしないと、ComboBoxは、設定したデータバインディングを無視して、コードを通じてプロパティの値を明示的に設定します。
ここでは、調整コントロールテンプレート内のContentPresenter要素がどのように見えるかです:
<ContentPresenter Margin="{TemplateBinding Padding}"
Content="{Binding Path=SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"
ContentTemplate="{Binding (a:ComboBoxExt.SelectionBoxItemTemplate), RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
</ContentPresenter>
最後に、これを使用するために、あなたのようなものだろう:
<ComboBox
Style="{StaticResource MyAdjustedComboBoxStyle}"
ItemTemplate="{StaticResource MyDropDownAreaTemplate}"
Behaviors:ComboBoxExt.SelectionBoxItemTemplate="{StaticResource MySelectionAreaTemplate}">
はい、そのようなことを、しかし、 SL3 ComboBoxにそのプロパティがないようですか? – user112889
奇数...ここでテストするSL3はありませんが、SL3が "他のバージョン"のボックスに表示されていなくても、MSDNのドキュメントに記載されています:.aspxの前にadd(VS.96)私のリンク)。おそらくベータ版の問題でしょうか?インテリセンスを無視してみてください。それがあれば、とにかくコンパイルしてください。 –
悲しいかな...私はそれを試して、これを得ました:XamlParseException。 AG_E_UNKNOWN_ERROR [Line:96 Position:135]そしてYes、96行目はSelectionBoxItemTemplateの行です。 – user112889