简体   繁体   中英

How to use binding property as a function parameter in C# Xamarin Forms

Maybe I missed the lesson about this, who knows...

This is the regular binding:

var picture = new Label();
picture.SetBinding(Label.TextProperty, new Binding("Picture"));

But, I want to use the value that is sent as "Picture" as a function parameter, for example:

LoadImageFromUrl("ValueOfPicturePropertyHere");

I will use the value of LoadImageFromUrl("ValueOfPicturePropertyHere") as an imageSource later on this project.

Any help will be appreciated. Thanks!

You can access the Picture property by using the binding context and then pass it to the Method you want.

var context = this.BindingContext;
LoadImageFromUrl(context.Picture);

the idea is that if you are binding a property on your view model you can easily get the latest value of it on code behind using the sample i provided

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM