2009-09-03 152 views

回答

3

事情是这样的:

<Style TargetType="{x:Type Button}"> 
<Setter Property="Template"> 
<Setter.Value> 
<ControlTemplate TargetType="{x:Type Button}"> 
<Grid> 
<Ellipse Width="64" Height="32" Fill="Blue" /> 
<ContentControl Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
</Grid> 
</ControlTemplate> 
</Setter.Value> 
</Setter> 
</Style> 

我没有测试的代码,但你应该明白了吧:)

编辑:当然是椭圆,具有填充属性,而不是背景。

安德烈

+0

这是在xaml中进行的吗? – AwkwardCoder 2009-09-03 15:27:52

+0

您可以将它放在任何.Resources部分,位于Button的“视觉水平”上方。下面的每个按钮都将是椭圆形的。例如: <按钮内容= “测试”/> Andrej 2009-09-03 15:48:37

1

下面的代码可以直接在自己的窗口和支持IsPressed和IsMouseOver触发器。

<Window.Resources> 

    <ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type Button}"> 
     <Grid> 
      <Ellipse Fill="White" Stroke="Black" VerticalAlignment="Top" Height="32" x:Name="theEllipse"/> 
      <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/> 
     </Grid> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Fill" Value="Yellow" TargetName="theEllipse"/> 
      </Trigger> 
      <Trigger Property="IsPressed" Value="True"> 
       <Setter Property="Fill" Value="Gray" TargetName="theEllipse"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 

</Window.Resources> 

<Grid x:Name="LayoutRoot"> 
    <Button HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Content="Button" Template="{DynamicResource ButtonControlTemplate}"/> 
</Grid>