gpt4 book ai didi

c# - 为什么为 BitmapImage 对象设置 URISource 需要 Begin 和 End 初始化?

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:00 25 4
gpt4 key购买 nike

我试图通过隐藏代码设置 wpf 图像类的源属性,但由于未知原因它无法正常工作。

我的代码是这样的

 1 BitmapImage img = new BitmapImage();
2 img.UriSource = new Uri("C:\\data\\pictures\dkn.jpg");
3 pict.Source = img;

然后我做了一些谷歌搜索,发现我需要像下面这样更改我的代码。

 1 BitmapImage img = new BitmapImage();
2 img.BeginInit();
3 img.UriSource = new Uri("C:\\data\\pictures\dkn.jpg");
4 img.EndInit();
5 pict.Source = img;

但我无法理解上面的第 2 行和第 4 行。在设置 urisource 属性之前和之后开始和结束初始化的意义是什么。我期望 urisource 属性的行为与普通的 clr 属性一样。

请有任何想法。

最佳答案

Begin 和 End init 指定对象支持一个简单的、事务处理的属性批量初始化通知 - MSDN

关于c# - 为什么为 BitmapImage 对象设置 URISource 需要 Begin 和 End 初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10752914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com