Do you want to make your Xamarin forms and dotnet Maui applications,
even more performant look no further than XAML compile the bindings.
This piece of technology built directly into Xamarin forms and Donna Maui enables
to make your XAML bindings eight times faster with just a single line of code.
I'm going to walk through everything you need to know.
Hey everyone.
I'm James Monson, Magna.
And I'm back with another video, sort of in the tips and tricks section.
I would say over here on my channel, of course, I have a full Xamarin
one-on-one and been talking about all of the dinette Mallory preview.
So definitely subscribe, ending that notification bell.
And Hey, at any time you're watching this video and you like it, or
just, Hey, you like it right now hit that like button that goes into
the Google algorithm of goodness.
Just jam on it.
It'll make me happy.
And it really helps my channel.
I appreciate.
All right.
So we're writing XAML all day, you know, and there it's enabling us
to build and construct our user interfaces and get really complex.
We've talked about MVVM one-on-one XAML one-on-one advances in a
different list, views and collection views, and really advancing out
building complex user interfaces.
The thing is.
That as things get more complex, you have a lot more data bindings in place,
which means Xamarin forms and Donna and Maui are subscribing to more things.
More Samuel is being parsed or XAML is getting bigger.
So we want to make it faster.
We want to resolve those bindings faster.
And additionally, we want to help the tooling, know what we're
talking about on every page or every control that we're coding.
And we want to enable it to give us error checking when
we're building our applications.
So you can do that with compiled bindings.
It makes it super simple to go off and build faster applications because
your XAML will be parsed and the data bindings will happen faster.
So let's check it out.
So, like I always say go to the documentation.
It's absolutely fantastic.
Literally here, Xamarin forms, compile bindings.
It's the same as dynamically compiled bindings.
It's very similar to a UWP is like X bind mechanism.
But what it does.
You know, if we look at what they say here is that there's two problems today.
One is that there's no compile time validation on binding
expressions, just a magical string.
And additionally, they're not super cost efficient because, um,
they're being resolved at runtime.
So if we use something like compiled by an Anglo, what does it do?
Well, it enables us to.
You know, it's not only XAML compilation, but set this ax data
type attribute that will enable those bindings to be resolved faster.
And you can do this on any control at any time.
And additionally, it works with items inside of list, views, or
collection views, anything with the item source and item template.
So check this out.
The biggest thing that I want to talk about here is that a compiled binder.
Here enables your one way, one way to source in two way.
Binding severes.
Eight times faster.
That is crazy than classic bindings.
Um, it also talks about how setting binding contacts will be five times
faster than not setting binding contacts.
And then of course, seven times quicker when you're using one time binding
up on your binding context, too.
A lot of advantages here and it just takes a single line of code.
So let's hop over to the coffee application that had been building
out on the 1 0 1 series over here.
So definitely check that out up there.
I'll put a bell over there for it.
Let's make this a little bit big.
There we go.
So what do we have?
Well, this page right now, uh, you know, as a coffee page,
it has a binding context set.
So this is our view model binding context, and I'm just doing it in code.
Um, you also might be doing this in the code behind, and in which, in that case,
you may not get better IntelliSense or error checking or anything like that.
Down here.
We just have a list view.
It has an item template, and then it has a header and footer.
And we're going to add a group patter template because it's
going to be grouped as well.
I'm going to talk about why we're going to do that.
Uh, inside of this is application well, so what do we need to
do to enable, uh, binding.
What we're need to do first is make sure that we're exposing the
property types that are going to be inside of our page, or maybe inside
of our list viewer collection view.
So here, what I've done is I've brought in my name space right here for view models.
And then I've also brought in a namespace for model.
So we look at my model folder over here.
Inside of my, uh, application.
So inside of my shared up here, there we go.
We'll see that that is inside of my coffee.
So we have coffee here and we also have our, of course
coffee equipment view model.
So a few things that visual studio, 2019 and 2022 will do for you automatically
is that we can tell that actually.
It is telling me what this little.dot.here that the coffee groups
two on my items versus not found, and that it will create it for me.
But if I go into my view models, which is going again, be this
coffee equipment, we can see that I actually have coffee's groups.
So I just had a typo there.
Well, since we're not using company.
Bindings at this point, the IntelliSense is smart enough, but it's not like a
build air look like build successful, no errors, everything like that.
So we're going to use a X data type that is a compiled binding.
So anywhere on the content page, or it might be a content view or any the X data.
And then what we're going to do is we're going to tell it in this
case, what the binding context is like, what is the data type of this?
And what we're going to say is this is going to be view, model
coffee, equipment view model.
So this here pairs with the binding.
Now I don't have to be using this here.
I can actually turn this off and set it in my code behind.
I'd still get enhanced IntelliSense in drop-downs and.
I will then get the compile time checking.
So like, actually it was compiled this one more time.
Now that I just had a one line of code right here and what we'll see right away.
Look at this coffee groups too.
Not fast.
Wow.
So we won't even let me debug my application because I have
a typo inside side of the code.
And if I tap on it, it takes you right to the line of code.
That's really, really nice when I'm writing a lot of code
or copying and pasting code.
It may have that issue where I type out something.
So let's go and get rid of that.
And let's just go ahead and build it up one more time.
So now it's going to say a few things.
We see another air down here, which is that the image property
is not found well what's going on.
Cause I set up the data type, right?
It's at the datatype well, here's the thing I'm now inside of the list
view, or you might be inside of a collection, viewer carousel view.
And now right here, this item template, isn't for it.
Isn't for this coffee view model, it's for the item inside of it, which is my coffee.
All right.
So here's what we need to do.
Is on the data template, which you have data type lens on just
about everything that has a, you know, a looping list of items.
We're going to put an X data type on that.
So X data type, and then what we're going to do here is we're
going to put models, coffee.
Okay.
Because the model is the coffee, the actual item inside of here.
So now what I can do here is I can go ahead and compile it again.
Yeah.
Well, we'll see, as we build successful, we're good to go.
And this even works here in this case where I have, you know,
uh, different bindings where I'm using relative, bindings up one,
it figures that out automatically because I have that data type set.
Now, if, for example, if I come in and I say, this is named two, for example, we
see we get that IntelliSense pop-up, but now we'll also get the air and I can click
on it and I can go ahead and fix that up.
There we go.
So let's go ahead and get rid of that too.
Compile it back up and we're good to go.
Now, this is working pretty good because we have a list
of coffees that are coming in.
But if you remember looking at this, this is actually in observable range
collection or observable collection of a grouping of string and coffee.
So this is going to be my header and this is going to be my item.
So everything is working great right now because this is just the
items coming in, but let's say.
I want to come in and I want to set the group header template here.
Let's go ahead and delete that there.
Right.
This is a group header template, and it's going to be taking
in the entire item over here.
So it actually, you can see here I'm binding to the key and it's
thinking like, where is this thing?
Where does it go?
If you look at what will be passed into the item, it's
actually me this entire grouping.
If I go in and go into this definition over here, if I go into it here, we'll
see that it's a grouping of T item.
Like it's an observable range collection, like as well.
So it's taking these items.
That's what it's going to be taking in one of the grouping items.
So we got to think to ourselves.
Hmm.
Well, how do we bind that here?
Because there's a data template here too, do that.
Well, sometimes let's just be honest, a museum in here, sometimes our
structures, or just really complex.
I mean, look at this grouping, it's a grouping of string of an object
and it's observable collection.
What does that syntax even look.
Well, sometimes it's too complex.
It's too complex for even me for, to describe in the XAML.
And honestly, the group had our template is one of those situations.
So what you're able to do is actually tell the data template.
With the data type.
So just kind of ignore this one, kind of null it out, and
that's what we're going to do.
We're going to say acts data type and I can try to do like MVVM and
I could try to do like a, you know, that's, that's a new namespace for
my MVVM helpers and bring that in.
But.
I dunno, it's just not even in there.
Like what is it?
It's a, it's a, it's a, you know, it's a, it's a generic,
so it's really complicated.
So what we're going to do here, and this may come up in your case, maybe it
won't, but we're going to say X colon.
No.
Okay.
Let's pick us up X colon.
So we use the squigglies here and this is special syntax.
So basically say, throw away, looking at data, um, compile bindings with the data
type for, for anything inside of here.
Just ignore it as fine.
Not a big deal.
Like just carry out basically.
Ignore this data template type and just carry on.
You're good to go.
And we see here that it's completely good to go.
No errors, anything like that.
And now our application, our data types are BA bindings are binding context.
Everything is a hundred bucks.
Now optimize and good to go.
When I run my apps, I'm going to see that perf performance, especially in
really big applications, with a lot of XAML and a lot of data binding going on.
So that's all you got to do.
I literally added three lines of code and now this page is way more proficient.
And if I have a lot of items, it's really going to really pay off.
Of course you want to make sure that you have your XAML compiled binding
turn on for the entire application.
If you don't have that on, I don't know.
That's bananas.
It's definitely a single line of code and it definitely help
you be way more successful.
Let me show you what that looks like here.
In fact, if you don't have this on, make sure you check this it's assembly export.
XAML compilation.
XAML compilation options, compile that is at the app level.
So everything in that assembly, actually the assembly level will
be automatically compiled there.
You can turn it off on a page by page basis if you need to.
But that is what you want to do is you want to set that on.
And that's the only way that compiled by news works.
Compiled by these and ammo compilation on, there you go.
You're asking him to be way more proficient.
You're going to have you ever have a better time developing your
applications with Xamarin forms and Don and Maui, because you're gonna
get that air checking built right in, and of course, visual studio will help
you by generating that code for you.
Like I've shown in another video.
Right up there.
All right.
I hope you found this really, really simple way of optimizing your apps.
Really cool and hope that you go and make your apps more proficient by adding X data
types all over the place and your Xamarin forms and dotnet Mallee applications.
I hope that you liked that.
If you did give it a thumbs up over there on YouTube, that really helps the
YouTube algorithm of goodness and helps.
Video would be recommended to other people that are interested
in this type of content.
Of course, if you want, don't forget to subscribe and hit that notification bell.
I put out new episodes every single week, and you'll get notified right on
your phone in the browser or in your email, who knows how YouTube works.
You'll get the notification.
And of course, if we're going to have a newsletter newsletter on
mountain, amanda.com and that I put out every single week, So you can
get insight into my life, not just code a little bit of code in there.
And of course I stream on Twitch at Twitch at TV slash James Bond.
The Magno, all the links are in the show notes below to this documentation, to the,
my coffee app sample, and so much more.
Thanks again for tuning in.
Thanks for watching.