您如何更改< path>填写C# [英] How do you change <path> fill in c#

查看:96
本文介绍了您如何更改< path>填写C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,程序员.

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

I have a question, that can I change imageBrush ImageSource? If I can, then how does it do that, I have tried many options and none of them seems not to work.

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

推荐答案

您可以通过投射Path的Fill属性来访问ImageBrush:

You can access the ImageBrush by casting the Path's Fill property:

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


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


Even simpler would be to set the x:Name property directly on the ImageBrush:

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

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

Now the XAML parser creates a public field that you can access in code behind:

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

这篇关于您如何更改&lt; path&gt;填写C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆