Conditional XAML in UWP
21K views
Nov 7, 2023
This tutorial explain about how to use the Conditional XAML concept in UWP
View Video Transcript
0:00
Hello all welcome to Universal Windows Programming tutorial
0:04
This tutorial I'm going to explain about how to use the conditional sample concept
0:11
So why condition is required? You can see Microsoft frequently releasing Windows 10 update features
0:20
So it started in 2015 then frequently releasing anniversary update, fall create update creator update creator update features like that is frequently releasing so each release some of the enhancement or new feature is coming so if you add the new features into our app let's say for example last release the Windows fall creator update features so if you are using that features it's fine but if your application running in the lower version let's say for example anniversary update or creator update
0:56
your application is running what are the new concept you has introduced your app those APAs those classes it won't be available the lower version so that we have to check if it is running the lower version no need to execute this functionality do some other things if this feature is available like do this else we can do this like that we can make so that's the reason condition is required
1:26
For example, it's an ytic created one sample application, just name is conditional
1:34
sample, this is just a nothing is a blank application. Here what I'm going to do, I'm checking one of the condition
1:45
Like for example, if APA information
1:55
So generally we are using the view model to check this appa is available or the new contract
2:02
available or like that. So here conditional example we are focusing on the universal API contract only
2:10
So I'm just checking is AP contract present or not. So here Windows dot foundation dot and universal and universal
2:25
cell APA contract contract so we're just checking if this AP is available contract
2:43
that is a second let's say for example conduct 5 is available or not yes so it's
2:53
available you some some two conditions going to execute this if block else execute this block so what I going to do I just adding on text box here text blog so text like okay I just make empty only here now
3:16
font size for example 25 foreground color like red so what I'm going to do here if
3:29
AP is present now one more I have to add the name of the control
3:37
TXT status so if the AP is present text hey I am new feature or okay new API
3:57
else dxt status here I am checking a I am only API that's it just build the
4:15
application so here what I am doing is I'm just checking if the universal
4:21
API contract major version the second present or not that means if the version 5 is
4:26
present running platform you have to change it to just display hey I'm new AP
4:34
else just display hey I'm old AP that's it one second rebuild it's going on it's
4:46
ready and just start the application deploy started see the condition is true so new API is available the new
5:12
contract is available a new API suppose for example testing purpose I
5:19
given some long number for example API version 25 is available or not so just start the application just application
5:29
here you can see that application
5:46
here you can see that API version 25 is not available so it's execute there
5:52
else case so that's the reason is discipline here I am only a pay okay fine I hope up to
6:03
this you can understand what is the use of AP information is AP contract present so this completely handling the view model code B it mage how to handle this concept in the ZAML so
6:20
this feature has introduced in the Windows 10 fall creator update the ZAML supporting
6:26
checking that API contract so you have to make sure your application version
6:35
the target version should be fall created update so I'm just testing purpose I
6:44
keep both versions on the same version only so going back to ZAML so here
6:50
we are going to add this concept so first what do you have to do we have to add
6:58
the name space name space I'm just telling present and this namespace we have to use in this one
7:14
Here we have to add the AP function, that API contract which we have seen in the view model
7:25
So here question mark, then just go to here, just check if AP contract present
7:35
Then, pause the information, which contract you want to check. So I'm just telling Windows API Universal AP contract
7:51
Then version, which version you want to check, 5. So this is the way we got to declare the Enzamel page
8:04
So next, if we added actually. So here two cases, if else
8:10
So if condition we added. So now we add to the else case also
8:15
So how to add the else case? The same code, just copy by list using not present
8:26
So I make the different namespace here, not present. And one more changes
8:32
Here you can see is API contract present. instead of that is AP contract not present you can execute this statement okay now what
8:44
I'm going to do I'm just adding one more text block this time I not declare any
8:54
name here this text block what I'm doing it I'm just making if AP present text field
9:04
AIMZAML condition Font if I just make four crown color let say for example green this is a
9:30
if condition so we had to add the else case also so else case what will do we
9:35
have to add you have to use not present namespace text a I am old zamel page here I
9:49
just change it here I am new zamel page that's it so we have to add the
10:00
namespace in the name space question mark here you have to add the contract name so is API contract present is
10:11
a pay contract not present that's it so for example if you want to use this
10:18
API based on the property of the new controls are like that whatever it is
10:24
so here I'm using the text block only so in the text blocks I'm just using
10:29
namespace dot text if the AP is present you have to display I am a new ZAMIPA
10:35
else not if not present I'm old Zammal page and just start the application
10:47
build starter
11:05
started so here you can see hey I'm new a sample page it's a little bit
11:14
overlapping I'll correct it just make grid row one okay so I'm just increasing the
11:28
number for example 15 increase a number This is a just testing purpose
11:43
In real scenario, it should be less than one only. Because Falk rated, University API contract is 5
11:50
So if you are running lower end, it should be less only. For testing purpose, I just keep the maximum number
11:59
So here you can see HAMO ZAMP. So that contract is not available, so we are executing the else case
12:11
I hope you can understand how to use the conditional ZAML concept in universal Windows programming
12:19
Thanks to all
#Programming
#Software
#Windows & .NET