相关疑难解决方法(0)

WPF ControlTemplates必须有TargetType吗?

WPF中的ControlTemplates是否需要TargetType?我正在重新设置一些控件,并注意到comboboxitem,listiviewitem和listboxitem都具有相同的模板:

    <ControlTemplate x:Key="ListBoxItemCT" TargetType="{x:Type ListBoxItem}">

    <Border x:Name="Bd" 
        SnapsToDevicePixels="true" 
        Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        Padding="{TemplateBinding Padding}"
        CornerRadius="1">
        <ContentPresenter x:Name="cpItemContent"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
            />
    </Border>

</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

是否可以删除TargetType并为所有三个模板设置一个模板?我试图这样做,但得到奇怪的错误和问题.我找不到ControlTemplates必须具有类型的任何特定参考.

.net wpf templates controltemplate targettype

10
推荐指数
1
解决办法
3669
查看次数

标签 统计

.net ×1

controltemplate ×1

targettype ×1

templates ×1

wpf ×1