开发者

xaml border style

开发者 https://www.devze.com 2023-04-11 19:31 出处:网络
I create style for buttons: <Style TargetType=\"{x:Type Button}\"> <Setter Property=\"Background\" Value=\"#8A88E1\"/>

I create style for buttons:

<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"
                        VerticalAli开发者_开发问答gnment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

It all OK. Now I want to write part of the style that would be looked around the ellipse boundary.


Erno beat me to the answer, but here's an example:

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

You should be able to bind the Stroke to the parent BorderBrush but I haven't tested it: Stroke="{TemplateBinding BorderBrush}". However, you won't be able to directly bind StrokeThickness to the parent BorderThickness as they're two different types (Ellipse.StrokeThickness is uniform and a simple double value whereas Button.BorderThickness is of type Thickness.).


There are two options:

  1. Set the Stroke and StrokeThickness of the ellipse or

  2. Add a template to the border and use an ellipse in the template.

Let me know if you need help with these.

0

精彩评论

暂无评论...
验证码 换一张
取 消