flexibility of syntax - XAML script ...
Posted: Thu Apr 06, 2017 11:54 am
Hi folks,
In other threads we have been seeing how XAML script can be used to represent the state of a WPF form at application 'start-up'. And how it can be used to simply define the initial state - by 'mark-up'.
Well, it took me quite a while, after starting to use XAML, before I realised that some (or much) of my confusion (or uncertainty) with XAML was due to it having the syntax flexibility of a human spoken language. There was often more than one way to do things in the XAML editor - short cuts and the likes.
I would like to start to discuss some of the syntax variations with you so that we can make more sense of other peoples WPF samples that we find on the web.
Recently we looked at the Button control and discussed how it was a 'Content' control - meaning that it had a 'Content' attribute (property) which could be assigned another control object.
Lets look at a common way to script this - check the following image :-
What we said in the previous thread was that 'content' could be placed directly within tags, and not mention the name of the attribute (Content) at all. This approach is often done for content controls other than Button, but the following is correct and acceptable - check below :-
But lets look at another way to express our syntax - one which produces this :-
The syntax used is shown below and in many ways is based on the standard way to define an attribute/property :-
By saying that the above XAML script is a common way to set attribute values, lets write the script for a pretty standard Button in this way - YES ! , it may seem a little odd to you BUT it is correct ;-0)
Now then folks, check to see that each of the pairs of tags represent a single attribute and that its value is within the tags.
This is not the way we usually see Width and Height being specified but it is one of those syntax variations we need to be able to read and understand. Check the above out carefully!
Enough for now, lunch is ready ;-0)
Speak later in a follow up to this thread, when we look at something a bit more complex, and the code to go with it as well.
Regards,
Phil.
Wales, UK.
In other threads we have been seeing how XAML script can be used to represent the state of a WPF form at application 'start-up'. And how it can be used to simply define the initial state - by 'mark-up'.
Well, it took me quite a while, after starting to use XAML, before I realised that some (or much) of my confusion (or uncertainty) with XAML was due to it having the syntax flexibility of a human spoken language. There was often more than one way to do things in the XAML editor - short cuts and the likes.
I would like to start to discuss some of the syntax variations with you so that we can make more sense of other peoples WPF samples that we find on the web.
Recently we looked at the Button control and discussed how it was a 'Content' control - meaning that it had a 'Content' attribute (property) which could be assigned another control object.
Lets look at a common way to script this - check the following image :-
What we said in the previous thread was that 'content' could be placed directly within tags, and not mention the name of the attribute (Content) at all. This approach is often done for content controls other than Button, but the following is correct and acceptable - check below :-
But lets look at another way to express our syntax - one which produces this :-
The syntax used is shown below and in many ways is based on the standard way to define an attribute/property :-
By saying that the above XAML script is a common way to set attribute values, lets write the script for a pretty standard Button in this way - YES ! , it may seem a little odd to you BUT it is correct ;-0)
Now then folks, check to see that each of the pairs of tags represent a single attribute and that its value is within the tags.
This is not the way we usually see Width and Height being specified but it is one of those syntax variations we need to be able to read and understand. Check the above out carefully!
Enough for now, lunch is ready ;-0)
Speak later in a follow up to this thread, when we look at something a bit more complex, and the code to go with it as well.
Regards,
Phil.
Wales, UK.