Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改填写c_C#_Wpf_Xaml_Path - Fatal编程技术网

C# 如何更改填写c

C# 如何更改填写c,c#,wpf,xaml,path,C#,Wpf,Xaml,Path,各位程序员好 我有一个问题,我可以更改imageBrush ImageSource吗? 如果可以的话,那么它是如何做到的呢?我尝试了很多选择,但似乎没有一个不起作用 <Path x:Name="PathImage"> <Path.Fill> <ImageBrush ImageSource="pic1.png"/> </Path.Fill> </Path> 可以通过强制转换路径的“填充”属性来访问Ima

各位程序员好

我有一个问题,我可以更改imageBrush ImageSource吗? 如果可以的话,那么它是如何做到的呢?我尝试了很多选择,但似乎没有一个不起作用

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

可以通过强制转换路径的“填充”属性来访问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>
试试这个:
imageBrush.ImageSource = new BitmapImage(new Uri());