如何在WPF应用程序中创建椭圆形按钮?
与主题完全一样,如何在WPF应用程序中创建椭圆形按钮?类似的内容:如何在WPF应用程序中创建椭圆形按钮?,wpf,button,Wpf,Button,与主题完全一样,如何在WPF应用程序中创建椭圆形按钮?类似的内容: <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <Ellipse Width="64" Height="32" Fill="Blue" />
<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>
我没有测试代码,但您应该知道:)
编辑:椭圆当然有填充属性而不是背景
安德烈像这样:
<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>
我没有测试代码,但您应该知道:)
编辑:椭圆当然有填充属性而不是背景
Andrej以下代码可以直接进入您的窗口,并支持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>
以下代码可以直接进入您的窗口,并支持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>
这在xaml中放在哪里?您可以将其放在按钮“可视级别”上方的任何.Resources部分中。下面的每个按钮都将是椭圆形的。例如:这个在xaml中放在哪里?您可以将它放在按钮“可视级别”上方的任何.Resources部分中。下面的每个按钮都将是椭圆形的。例如: