【问题标题】:Update path color after it has been added to a canvas将路径颜色添加到画布后更新路径颜色
【发布时间】:2013-02-24 21:17:40
【问题描述】:

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

【问题讨论】:

  • 你试过任何东西吗?
  • 找到要改的路径,改颜色。
  • 是的,我尝试从画布中获取路径,然后获取该引用并更新它,但没有任何反应。
  • 您必须发布更多信息才能让我们为您提供帮助。您尝试过的代码在哪里,有什么不好的地方。

标签: c# wpf canvas path controls


【解决方案1】:

YourPath.Fill = Brushes.Blue;

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.
        }
    }
}

【讨论】:

    猜你喜欢
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多