ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Three Data-Binding Tricks for Xamarin.Forms You Didn't Know!

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • This video will show you three (or four?) databinding tricks that you might not know about. We will see how the different binding modes work, implement string format and last but not least we will learn how to use fallback values.
    🛑 Don't forget to subscribe to my channel for more cool content: th-cam.com/users/GeraldVerslui...
    🔗 Links
    Sample code repo: github.com/jfversluis/XFBindi...
    Basic Data Binding: • Basic Data Binding in ...
    Data Binding Scopes Video: • Xamarin.Forms ListView...
    ValueConverters Video: • Using ValueConverters ...
    Databinding Modes Docs: docs.microsoft.com/xamarin/xa...
    Data Binding String Formatting Docs: docs.microsoft.com/xamarin/xa...
    String Format Docs: docs.microsoft.com/dotnet/sta...
    Binding Fallback Docs: docs.microsoft.com/xamarin/xa...
    Xamarin Forms Repo: github.com/xamarin/Xamarin.Forms
    Xamarin.Forms Databinding Docs: docs.microsoft.com/xamarin/xa...
    ⏱ Timestamps
    0:00 Intro
    0:30 Sample App Outline
    0:47 Setup Bindingcontext
    2:14 Implement Basic Databinding
    3:04 Databinding Path
    3:44 Databinding Non-String Values
    5:00 Databinding Modes: OneTime, OneWay, OneWayToSource and TwoWay
    10:40 StringFormat in Your Databinding, Convert Double to Integer
    13:00 FallbackValue and TargetNullValue
    17:05 Did You Deserve a Seal of Approval Sticker?!
    17:34 Like, Subscribe, Thanks!
    🎥 Video edited with Camtasia (ref): techsmith.z6rjha.net/AJoeD
    🙋‍♂️ Also find my...
    Blog: blog.verslu.is
    Twitch: / jfversluis
    All the rest: jfversluis.dev

ความคิดเห็น • 72

  • @jfversluis
    @jfversluis  3 ปีที่แล้ว +7

    Should I have that Gerald seal of approval printed? Maybe I should make a course here and let that be the reward...

    • @pavelkravchenko2810
      @pavelkravchenko2810 2 ปีที่แล้ว

      What about binding in Templates/ DataTemplate, RelativeSource , Source, Reference? There's tons of questions in the internet about it))))

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Maybe this helps: th-cam.com/play/PLfbOp004UaYWOuVUuEtGlpkDIC1houhn_.html

  • @eekayonline1561
    @eekayonline1561 3 ปีที่แล้ว +3

    Didn't know about the fallbacks so that's one thing I've learned for sure!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      See, theory still holds 😎

  • @ArielErlijman
    @ArielErlijman 2 ปีที่แล้ว +1

    Another life saving tip! I´ve just had to put a "Total: " + list.Count in a label and was able to do it with the StringFormat ! awesome. Thx again.

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Woohoo! Perfect! Well done!

  • @CezarWagenheimer
    @CezarWagenheimer 3 ปีที่แล้ว +2

    I didn't know about TargetNullValue and FallbackValue! It's very useful! Thanks for sharing it!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Ha! My theory still holds! Glad you learned something!

  • @issacproton7885
    @issacproton7885 3 ปีที่แล้ว +4

    Yes, I knew all of them. By the way, The contents are getting more Impressive as well as very effective to all Xamarin Developers. Thanks a lot for all the contents you're creating. It just Amazing!!!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Really?! I need to get you that sticker then ;)
      Thank you for the kind words Issac! I really enjoy doing it. Thanks for all the support!

    • @issacproton7885
      @issacproton7885 3 ปีที่แล้ว +1

      @@jfversluis You're doing just great! Everything is getting better.

  • @argonjs
    @argonjs 3 ปีที่แล้ว +2

    Appreciate your effort. Keep the good work up.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thanks a ton Aruna, I definitely will!

  • @vijaichaudhary8092
    @vijaichaudhary8092 2 ปีที่แล้ว

    Thanks you..Learn all of them

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Great Vijai! Thank you for watching!

  • @SayyadHasan
    @SayyadHasan 3 ปีที่แล้ว

    Excellent, truly I was not aware of TargetNullValue and FallbackValue

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Glad you learned something!

  • @rajeshjha3681
    @rajeshjha3681 3 ปีที่แล้ว

    Nice video on Data Binding.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Thank you for joining me again Rajesh!

  • @derrickwright1701
    @derrickwright1701 3 ปีที่แล้ว +1

    Thanks for the video! Ive been struggling to data-bind for a few days now and your video helped a bit. Does this also work with listviews or how would you approach binding to an object property for a listview? Thanks

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Glad to read it helped! I already replied to your other comment, let me know how I can help you. Else let's jump on email or something for some better communication :)

  • @guywangueu9817
    @guywangueu9817 2 ปีที่แล้ว

    So good you are the best

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Thanks so much! 🤗

  • @jxndwl
    @jxndwl 3 ปีที่แล้ว

    Useful tips, thanks.
    I really rely on XAML designer in WPF to setting up binding expression(the little yellow rectangle), remember all the gramma for databinding is very hard for me, especially for serial of RelativeSource. Hope one day Xamarin forms team make XAML designer to have the GUI way to setting DataBinding.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thank you so much! We can always hope, but I don't think a XAML designer is something that will come :(
      If there is anything I can do for you, don't hesitate to reach out!

  • @GV_Frames
    @GV_Frames 2 ปีที่แล้ว

    good useful to me

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Great! Thanks for letting me know!

  • @JasonPurkiss
    @JasonPurkiss 3 ปีที่แล้ว +1

    thanks for a great video, would you know how i would go about implementing phpickerviewcontroller in IOS 14 to access photos or should i just wait for James montemagno to update his media plugin? im quite disappointed in my self that i just dont know where to start :(

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thank you Jason! First of all: don't be disappointed! This stuff is hard to figure out, so don't feel bad. Second; I guess it's all about the investment you want to make vs how bad you need it. If you can wait for someone to implement it, then that is the easy route. If you need it/want it sooner or with more guarantees that you will even actually get it, start rolling your own.
      You could look at how the Media Plugin does the picking today. If you're reaaaaally lucky, just rename everything to PHPickerViewController and you're done, probably a little bit more work than that, if you're not so lucky it will be a can or works and you need to reimplement the whole thing.
      Having all that said; I think the Media Plugin bits are slowly rolled into Essentials, so I wouldn't expect any big updates on the Media Plugin anymore, rather look at Essentials. I see they already have an open issue for this here: github.com/xamarin/Essentials/issues/1402 the milestone says 1.6, so it might be in there soon...?
      Hope this helps you a tiny bit :)

  • @jayveebelano9041
    @jayveebelano9041 2 ปีที่แล้ว

    interesting vid very informative

  • @adamdiment8385
    @adamdiment8385 3 ปีที่แล้ว

    Thanks Gerald, I enjoyed this video. I knew them all except the difference between targetnullvalue and fallback value I think :-) Oh wait, and that Binding X is shorthand for Binding Path=X.... who knew! So you can teach an old dog new tricks...
    A couple of things I would like to hear about in follow up vids
    1) Using the Source property of binding
    2) More complex stringformat bindings including multiple properties
    3) The pros and cons of compiled bindings vs runtime bindings.
    Thanks!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Ha! It's funny how these things that you take for granted still hold some secrets, right?! Glad you found it helpful!
      Those are amazing ideas for follow-ups, thank you so much for the suggestions, I have put them on the list and will definitely work on that. Do you have anything specific in mind for number 1? Are you looking for use-cases? Or how to actually implement it?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Actually, have a look at this video: th-cam.com/video/Or_qn8i8jVM/w-d-xo.html this talks about the scope :)

    • @adamdiment8385
      @adamdiment8385 3 ปีที่แล้ว

      ​@@jfversluis Thanks Gerald. Re number 1 - both I guess. I've used x:Reference bindings on my custom content views to set the context of the view elements to the content view itself, and then bind to my custom properties.
      But haven't ever really delved any further into what more can be accomplished with "Source". I wonder if I'm missing some tricks to simplify my xaml that you might know.
      Some questions that come to mind...
      a) Reading through the docs I think that the "Source" IS the binding context right? So what would be the difference between setting "BindingContext" on a view, vs setting Source within a {Binding Path=..., Source=...}? Are they equivalent? Is there a time to use one or the other?
      For instance, after hacking around a bit this morning with some very bad xaml, (xaml screenshot: gyazo.com/85a29a404a57210d5648ffad0d8589a1 result: gyazo.com/476aed93d1128616c3622e8231650132) it seems that setting the source manually for a single property of a parent element might be a good way to break out of the binding context for a parent view, without affecting the binding context of subviews of that parent. Whereas setting the "BindingContext" on a parent view, would also set the context for all subviews. Is this right? And are there other factors to consider / benefits to gain from one approach or the other?
      b) Can x:Reference / manually setting the Source property have benefits / uses in an MVVM app? The docs seem to focus on use cases where the code behind is the binding context. E.g. Sliders controlling label rotation etc. Interesting but not super practical for MVVM.
      Thanks!
      I'm enjoying the null pointers podcast too btw.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      @@adamdiment8385 Thank you so much Adam! Did you also see my previous reply with the link to a video where I talk about the Source? Here it is again: th-cam.com/video/Or_qn8i8jVM/w-d-xo.html
      a) you're absolutely right, you are effectively setting the BindingContext with this
      b) I think the biggest scenario for this would be whenever you are in an ItemTemplate and want to set the Source to your ViewModel rather than the item in your collection. One example for that would be where you have a swipe action on an item in your collection. I.e. to delete it. You probably want to set the Source to reference the BindingContext of your ViewModel which has a delete Command, rather than implementing the delete Command on the item in your collection. Does that make sense? :)

  • @iancarroll3918
    @iancarroll3918 3 ปีที่แล้ว +1

    Great work. Is it possible to have the number format bound to a property?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      You mean like this? docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/data-binding/string-formatting

  • @marthinch
    @marthinch 3 ปีที่แล้ว

    I have a question, can we create generic page by using xaml in xamarin form? I've tried to create a generic page but I use c# behind code to create the page and I just want to know if there's a way to create generic page by using xaml in xamarin form.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thanks for your question Marthin! What do you mean exactly by generic page? Maybe it's easier to discuss if you send me an email :) please find my address on github.com/jfversluis and we will discuss there.

  • @poorneshv7532
    @poorneshv7532 2 ปีที่แล้ว

    Hey Gerald Thank you very much for your content. Can you do videos on UI Animations? We don't have much content on it online .

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว +1

      Unfortunately I’m not the best at that myself 😅 you might want to keep you eye on this blog: blog.bijington.com

  • @heinzd5523
    @heinzd5523 2 ปีที่แล้ว

    Is there a way for one Content Page to bind to two ViewModel pages? ie: have two Bindingcontext statements in the code behind/

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      No and tbh I don’t think that’s something you should want. Each element on the page can have its own BindingContext so you might be able to do something with that, but again; I don’t think you’ll have a fun time maintaining that

  • @umermahmood6366
    @umermahmood6366 3 ปีที่แล้ว

    Please make a video on use case when our page has two or three different sections (stack layouts or grids), Each section is binded to a specific property. Where each property basically represents an object with multiple fields. Or just to begin with, two stack layouts, binded to two different properties, where each property has some string, some number, some double. Thank you.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      I think the thing you're describing is possible, but why not create a view model that has the properties that you need? That is what view models are for, to not have many different objects providing all the properties. Then from the view model you should propagate the values to the right models and continue processing from there. Hope I understood you correctly :)

  • @Swarajcookingnfun
    @Swarajcookingnfun 2 ปีที่แล้ว

    Hey Gerald!! How we can implement required field validation in entry box?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      You probably want to check this out: th-cam.com/video/rRn2k3l0P8k/w-d-xo.html

  • @raffimansoor3739
    @raffimansoor3739 3 ปีที่แล้ว +1

    Hi @Gerald ..awesome video...can you please make a video about Xamarin Forms 5.0

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Absolutely! Just see what is new with a little demo? Did you also see this episode of the Xamarin Show covering this? th-cam.com/video/ttF80UnrJAg/w-d-xo.html

    • @raffimansoor3739
      @raffimansoor3739 3 ปีที่แล้ว

      @@jfversluis Thanks a lot ..This is awesome ..😀

  • @AMIRKHAN-dm2fm
    @AMIRKHAN-dm2fm 3 ปีที่แล้ว +1

    Thanks but tell me one thing if I don't have iOS or mac device then how i can test my xamarin.iOs application?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      If you don't have a Mac or iOS device it's going to be hard. You can look into renting a Mac with a solution like www.macincloud.com/ if you have just an iOS device you should look into Hot Reload which allows you to debug with a Mac but just an iOS device and a developer account. Unfortunately, Apple does not allow to run macOS and therefore Xcode and the Simulator to run on anything but their own hardware

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 3 ปีที่แล้ว +1

      @@jfversluis Ok Thank you so much

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      @@AMIRKHAN-dm2fm No problem!

  • @Elsa-jw3xe
    @Elsa-jw3xe 3 ปีที่แล้ว

    Love the video, good work. Unfortunately i did not know it all, so no sticker for me bleeeh :S

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Haha o no! Well, not a sticker, but you did win in knowledge! :D
      There will be other chances where I'm sure you will get one! Thanks for watching!

  • @Mafyou75
    @Mafyou75 2 ปีที่แล้ว

    I prefere setting my databinding context in Xaml. With that, you got intellisense !

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Absolutely true! Luckily we have options and each can use their own preferred way :)

    • @Mafyou75
      @Mafyou75 2 ปีที่แล้ว

      Then, why turn off intellisense?

  • @matteoc7084
    @matteoc7084 3 ปีที่แล้ว

    How can I bind a value that uses Preferences.Get?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Easiest is to create a property that just returns that value :)

  • @JohnFarrellDev
    @JohnFarrellDev 3 ปีที่แล้ว

    Nice Wizard hat (g)

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Haha thank you! 🧙‍♀️

  • @andreybundin6102
    @andreybundin6102 2 ปีที่แล้ว

    How to bind Content.TranslationX of gesture container in XAML?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      It's just another bindable property so it shouldn't be any different than any other property you are data binding to. Do you have issues with it?

    • @andreybundin6102
      @andreybundin6102 2 ปีที่แล้ว

      @@jfversluis yes, I have. "TranslationX" is bindable property and it is able to bind, but "Content.TranslationX" is different and it not do. Content.TranslationX is attached property of gesture container, through it you do not aproach to the container, but to his children, as i think. I spend almost half year for this issue, but do not have answer yet. It is not importent if you do not use MVVM, beacuse you may call for this property in code behinde as "name of container".Content.TranslationX. I only have some not very good result: made the container static in auto assambler and then i can approach to container in VM like in code behind

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว +1

      @@andreybundin6102 Ah yeah I think with attached properties it doesn't work out of the box. So if you made something that works, although not that nice, stick with it for now :D

    • @andreybundin6102
      @andreybundin6102 2 ปีที่แล้ว

      @@jfversluis maybe there is some way change the "box", maybe through CLR or by use nuget? And can i make example static in XAML?

    • @andreybundin6102
      @andreybundin6102 2 ปีที่แล้ว

      @@jfversluis my way is bad, becuse every chang in XAML recompile assambler (sorry, maybe i call it not correct) and i must writ static in it again :)