将路径颜色添加到画布后更新路径颜色
本文关键字:路径 颜色 更新 添加 | 更新日期: 2023-09-27 18:00:46
我有一个画布,上面有很多路径。在将路径添加到画布后的某个时间,我需要更改路径的填充颜色。我该怎么做?
YourPath.Fill=画笔。蓝色;
http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill.aspx
工作示例:
标记
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="paths.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Path x:Name="myPath" Data="M101,190 C463,145 581.5,186.5 473.5,279.5 365.5,372.5 153.50002,345.50016 122.50001,271.49998 91.499996,197.4998 101,190 101,190 z" Fill="#FFF4F4F5" Margin="84.628,112.772,126.105,161.198" Stretch="Fill" Stroke="Black"/>
<Button Content="Change Color" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="122" Margin="0,0,139,63.04" Click="Button_Click"/>
</Grid>
</Window>
代码
namespace paths
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
myPath.Fill = Brushes.Blue;
// TODO: Add event handler implementation here.
}
}
}