C# 将路径颜色添加到画布后更新路径颜色

C# 将路径颜色添加到画布后更新路径颜色,c#,wpf,canvas,path,controls,C#,Wpf,Canvas,Path,Controls,我有一张画布,上面有许多路径。将路径添加到画布后,我需要更改路径的填充颜色。我该怎么做?YourPath.Fill=brusks.Blue 工作示例: 标记 <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="Win

我有一张画布,上面有许多路径。将路径添加到画布后,我需要更改路径的填充颜色。我该怎么做?

YourPath.Fill=brusks.Blue

工作示例:

标记

<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.
        }
    }
}
命名空间路径
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
this.InitializeComponent();
//在此点下方插入创建对象所需的代码。
}
私有无效按钮\u单击(对象发送者,System.Windows.RoutedEventArgs e)
{
myPath.Fill=画笔.Blue;
//TODO:在此处添加事件处理程序实现。
}
}
}

您尝试过什么吗?找到您想要更改的路径并更改颜色。是的,我尝试过从画布上抓取路径,然后获取该引用并更新它,但没有任何效果。您必须发布更多信息,以便我们帮助您。您尝试过的代码在哪里,哪些代码不起作用。