Как добавить бордер к закругленной кнопке WPF
Пытаюсь добавить бордер к закругленной кнопке, но результата не выдает. Но если убрать закругление, то все работает. Как это исправить? Использую шаблоны.
Шаблон кнопки:
<Style TargetType="Button" x:Key="MenuBtn">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="#3d0109"/>
<Setter Property="Margin" Value="94,35,94,90"/> <!--Value="94,35,94,98"-->
<Setter Property="FontSize" Value="30"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Red" CornerRadius="10">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="10"/>
</Style>
Xaml:
<Button Style="{StaticResource MenuBtn}" BorderBrush="Blue" BorderThickness="10" Content="Play" Grid.Row="2" Grid.Column="6" Grid.ColumnSpan="3" Grid.RowSpan="2"/>
<Button Style="{StaticResource MenuBtn}" Content="Load" Grid.Row="3" Grid.Column="6" Grid.ColumnSpan="3" Grid.RowSpan="2" />
<Button Style="{StaticResource MenuBtn}" Content="Settings" Grid.Row="4" Grid.Column="6" Grid.ColumnSpan="3" Grid.RowSpan="2"/>
Ответы (2 шт):
Автор решения: MX32
→ Ссылка
В шаблоне закругление есть свойство <Border/> туда мы и вписываем настройки бордера
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Red" CornerRadius="10" BorderThickness="2" BorderBrush="Blue">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
Автор решения: AlexanderSt
→ Ссылка
Вы пытаетесь добавить BorderBrush и BorderThickness к самой кнопке, а нужно передать их вложенному в темплейт элементу Border:
<Window.Resources>
<Style TargetType="Button" x:Key="MenuBtn">
<Setter Property="Background" Value="Red"/>
<Setter Property="FontSize" Value="30"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Red" CornerRadius="10"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10">
<Button Content="..." Width="80" Style="{StaticResource MenuBtn}"/>
<Button Style="{StaticResource MenuBtn}" BorderBrush="Blue" BorderThickness="10" Content="Play" />
<Button Style="{StaticResource MenuBtn}" Content="Load" />
<Button Style="{StaticResource MenuBtn}" Content="Settings" />
<TextBox Width="300" Text="{Binding OutText, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</Window>