Change function into dependencyproperty
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();
精彩评论