开发者

Change function into dependencyproperty

开发者 https://www.devze.com 2023-02-17 05:14 出处:网络
I am new to XAML and WPF and I am learning about DependencyProperty and Path. For example, I have a function like this

I am new to XAML and WPF and I am learning about DependencyProperty and Path. For example, I have a function like this

public byte[] DownloadPicture()
{
    WebClient webClient = new WebClient();
    byte[] data;
    data = webClient.DownloadData("https://graph.facebook.com/4/picture&type=large");       
    return data;
}

and I have dependencyproperty like this

public static DependencyProperty Do开发者_开发百科wnloadPicProperty = 
DependencyProperty.Register("DownloadPic", typeof(byte), 
    typeof(ImageControl), new PropertyMetadata(false));        

How can I connect the DependencyProperty with the DownloadPicture function I wrote? Any suggestions? What should I write in the CLR wrapper?


You can get and set the value of a dependency property by adding a standard property to the control as well.

public static DependencyProperty DownloadPicProperty =
    DependencyProperty.Register("DownloadPic", typeof(byte[]), typeof(ImageControl));

public byte[] DownloadPic
{
    get { return (byte[])GetValue(DownloadPicProperty); }
    set { SetValue(DownloadPicProperty, value); }
}

...
ImageControl imageControl = ...;
imageControl.DownloadPic = DownloadPicture();
0

精彩评论

暂无评论...
验证码 换一张
取 消