如何更改<path>填写c#</path>

时间:2014-04-26 15:12:32

标签: c# wpf xaml path

Hello其他程序员。

我有一个问题,我可以更改imageBrush ImageSource吗? 如果可以,那么它是如何做到的,我已经尝试了很多选项,但似乎没有任何选择。

<Path x:Name="PathImage">
    <Path.Fill>
        <ImageBrush ImageSource="pic1.png"/>
    </Path.Fill> 
</Path>

1 个答案:

答案 0 :(得分:0)

您可以通过强制转换Path的Fill属性来访问ImageBrush:

var imageBrush = PathImage.Fill as ImageBrush;
imageBrush.ImageSource = new BitmapImage(new Uri());

更简单的是直接在ImageBrush上设置x:Name属性:

<Path x:Name="PathImage">
    <Path.Fill>
        <ImageBrush x:Name="imageBrush" ImageSource="pic1.png"/>
    </Path.Fill> 
</Path>

现在,XAML解析器创建了一个公共字段,您可以在后面的代码中访问:

imageBrush.ImageSource = new BitmapImage(new Uri());