I have WPF triangle button which is made using Polygon-geometry:
<UserControl x:Class="Formats.Triangle_Down"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Formats"
mc:Ignorable="d" Height="100" Width="100">
<Grid Margin="0,0,10,10">
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="11*"/>
</Grid.RowDefinitions>
<Button Background="Transparent" Content="Button" Foreground="Transparent" Margin="0,0,50,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid Background="{TemplateBinding Background}">
<Polygon x:Name="triangle" Points="10,10 20,30 30,10" Stroke="Lime"
StrokeThickness="2" Fill="Lime" Margin="0,0,-91,-85">
</Polygon>
</Grid>
</Button.Template>
</Button>
</Grid>
So my question is: how can I change Background
color and Borderbrush
of my Button
using C# code?
When I use this:
button.Background = System.Windows.Media.Brushes.Red;
nothing changes (if I have not mistaken, because it doesn't change filling of polygon). I know the way to change color using "border"
<Border Background="{TemplateBinding Background}">
<Button.Content>
</Border>
But it doesn't suit me 'cause form of my button is triangle.
So, how can I solve this problem?