我有一张画布,上面有许多路径。将路径添加到画布后的某个时间,我需要更改路径的填充颜色。我该怎么做?
问问题
1475 次
1 回答
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.
}
}
}
于 2013-02-24T21:26:41.707 回答