【问题标题】:round combo box border圆形组合框边框
【发布时间】:2016-11-10 21:05:31
【问题描述】:

朋友 我发现这段代码可以制作圆形组合框,但我不知道如何使用

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

<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 中的组合框

【问题讨论】:

标签: c# wpf


【解决方案1】:

你在这里展示的这个模板只是一个基本的想法,但并不是真正有效的。您需要覆盖完整的默认模板并根据需要对其进行自定义。在您的 UserControl 资源中,从此链接 default combobox template 中创建一个模板(只需复制和粘贴)

<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" >

应该这样做。由于您没有为模板指定键名,因此组合框应自动选择一个新模板。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 2023-01-18
    • 2021-03-10
    相关资源
    最近更新 更多