【问题标题】:xaml border stylexml边框样式
【发布时间】:2011-10-11 00:28:09
【问题描述】:

我为按钮创建样式:

<Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="#8A88E1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid>
                        <Ellipse Fill="{TemplateBinding Background}"/>
                        <ContentPresenter HorizontalAlignment="Center"
                        VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

一切正常。现在我想写下椭圆边界周围的部分样式。

【问题讨论】:

  • 请把你的问题说清楚一点,这没有任何意义。
  • 我想创建带有边框的椭圆

标签: wpf xaml


【解决方案1】:

Erno 在答案上击败了我,但这里有一个例子:

<Style TargetType="{x:Type Button}">
  <Setter Property="Background" Value="#8A88E1"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Grid>
          <Ellipse Fill="{TemplateBinding Background}" Stroke="..." StrokeThickness="..." />
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

您应该能够将Stroke 绑定到父BorderBrush 但我还没有测试它:Stroke="{TemplateBinding BorderBrush}"。但是,您将无法直接将 StrokeThickness 绑定到父 BorderThickness,因为它们是两种不同的类型(Ellipse.StrokeThickness 是统一的,并且是简单的 double 值,而 Button.BorderThickness 的类型是 Thickness .)。

【讨论】:

    【解决方案2】:

    有两种选择:

    1. 设置椭圆的 Stroke 和 StrokeThickness 或

    2. 将模板添加到边框并在模板中使用椭圆。

    如果您在这些方面需要帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2012-09-24
      相关资源
      最近更新 更多