[英]How to make circle button in XAML and C# with customize style?
我是 XAML 新手,我的簡單游戲中的按鈕有問題。 我制作了一個圓形按鈕,我需要更改它的顏色,但我的按鈕沒有提供按鈕的默認樣式,如動畫、懸停時指針更改、單擊動畫等,它的顏色也不會改變。
這是我的 XAML:
<Page.Resources>
<SolidColorBrush x:Key="RedColorXX" Color="Red" />
</Page.Resources>
<Button x:Name="btnRed" Style="{StaticResource btnColor}" Content="Red" HorizontalAlignment="Left" Height="228" Margin="62,261,0,0" VerticalAlignment="Top" Width="228" Background="#FFCA6969" Click="colors_Click" FontSize="0.01" BorderBrush="Azure" Grid.Column="1" >
<Button.Template >
<ControlTemplate TargetType="Button" >
<Grid >
<Path Stretch="Uniform" UseLayoutRounding="False" Fill="#FFCA6969">
<Path.Data>
<EllipseGeometry RadiusX="1" RadiusY="1"/>
</Path.Data>
</Path>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
和不起作用的顏色更改代碼!
btnRed.Background = (SolidColorBrush)Resources["RedColorXX"];
例如我把你的 fill="#FFCA6969" 變成黃色:
<Button x:Name="btnRed" Content="Red" HorizontalAlignment="Left" Height="228" Margin="100,35,0,0" VerticalAlignment="Top" Width="228" Background="#FFCA6969" Click="colors_Click" FontSize="0.01" BorderBrush="Azure" >
<Button.Template >
<ControlTemplate TargetType="Button" >
<Grid >
<Path Stretch="Uniform" UseLayoutRounding="False" Fill="Yellow">
<Path.Data>
<EllipseGeometry RadiusX="1" RadiusY="1"/>
</Path.Data>
</Path>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.