圆形组合框边框

本文关键字:边框 组合 | 更新日期: 2023-09-27 18:17:17

friends我找到这个代码来制作圆形组合框,但我不知道如何使用

有没有人可以帮助如何使用这段代码

<Style TargetType="{x:Type ComboBox}">    
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ComboBox}">
        <Border CornerRadius="5">
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

我应该怎么做才能将此代码应用于 WPF 中的组合框

圆形组合框边框

您在此处显示的此模板只是一个基本概念,但并非真正有效。您需要覆盖完整的默认模板并根据需要对其进行自定义。在UserControl的资源内部,有一个模板(只需复制和粘贴(来自此链接的默认组合框模板

<UserControl.Resources>
<!-- paste the code here-->
<!--Control colors.-->
<Color x:Key="WindowColor">#FFE8EDF9</Color>
<Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color>
<Color x:Key="ContentAreaColorDark">#FF7381F9</Color>
….
<ControlTemplate x:Key="ComboBoxToggleButton"
                 TargetType="{x:Type ToggleButton}">
….
</UserControl.Resources>
Then modify the border radius in two places:
…
Grid.ColumnSpan="2"
            CornerRadius="<put a new radius here, for example 20>"
            BorderThickness="1">
…
And here
<Border Grid.Column="0"
            CornerRadius="<new value, for example 20>,0,0,<new value, for example 20>"
            Margin="1" >

这应该可以做到。由于您没有指定模板的键名称,因此组合框应自动选取一个新模板。