Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何指定combobox使用特定的ComboBoxItem模板_C#_Wpf_Combobox - Fatal编程技术网

C# 如何指定combobox使用特定的ComboBoxItem模板

C# 如何指定combobox使用特定的ComboBoxItem模板,c#,wpf,combobox,C#,Wpf,Combobox,我有一个wpf ComboboxItem模板,可以很好地工作。 我只希望它通过特定的组合框样式应用于特定的组合框。我不知道在组合框样式中的什么地方应该指向组合框项目样式。有什么建议吗 <Style TargetType="ComboBoxItem"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultS

我有一个wpf ComboboxItem模板,可以很好地工作。 我只希望它通过特定的组合框样式应用于特定的组合框。我不知道在组合框样式中的什么地方应该指向组合框项目样式。有什么建议吗

    <Style TargetType="ComboBoxItem">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <Border Name="Border" Padding="2" SnapsToDevicePixels="true" BorderThickness="1">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                       ...
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

...

...
根据评论更新:或者,作为样式的一部分:

<Style x:Key="s2" TargetType="ComboBox">
    <Setter Property="ItemTemplate" Value="{StaticResource s}"/>
</Style>


我认为应该在这里附近指定。Content=“{TemplateBinding ComboBox.SelectionBoxItem}”ContentTemplate=“{TemplateBinding ComboBox.SelectionBoxItemTemplate}”ContentTemplateSelector=“{TemplateBinding ItemTemplateSelector}”/>如何将您的重新响应作为样式的一部分?
<Style x:Key="s2" TargetType="ComboBox">
    <Setter Property="ItemTemplate" Value="{StaticResource s}"/>
</Style>