Q's about Windows Phone 8 App dev; Working through the Bob's, Clint's and Larry's tutorial
- Hi everyone!!
I just decided yesterday that I want to add some functionality to my new and first Windows Phone myself(got a Lumia 830, couldn't be happier!). Coming from a C and Python background, I am working/reading through the "Absolute Beginner Series For Windows Phone 8" to get a clear understanding of all the cool features which we can manipulate in Windows Phone. (Tutorial can be found at channel9 msdn , unfortunately I cannot write URL's yet) The reason I am writing here, is because I have some questions and I might get some more questions later on which I will also add in this first post. I am hoping somebody might be willing to (partially) answer them. It might be some of the questions are actually handled later on in the material so don't be afraid to tell me just that if you are familier with the material.
Thanks in advance!
Questions:
1. After reading section 3 on XAML, I was thinking if it might be possible to inherit one of the standard classes (like Textbox or Button) and add some common functionality that a lot of instance might share and then use thàt element in the XAML code. In other words, is it possible to add your own elements based on existing elements in XAML?
2. After thinking a little bit about how XAML works and what kind of functionality I would like to add in apps in the future, is it possible to "update" XAML code just like javascript updates HTML or is another mechanism usually used here? An example where you might use this: If a user clicks on a new Button and a new textbox must be inserted in the current page, you can of course instantiate the new Textbox in your C# code and add it as a children to the container. But XAML is used to create such content much more easily so how would you got about adding XAML code dynamically while also knowing that XAML code is actually compiled to C#? Is there like a function which you can use to inject XAML code from a C# script?
Again guys and girls, thanks very much for reading/answering any of my questions!02-21-2015 08:07 AMLike 0 - After reading section 3 on XAML, I was thinking if it might be possible to inherit one of the standard classes (like Textbox or Button) and add some common functionality that a lot of instance might share and then use thàt element in the XAML code. In other words, is it possible to add your own elements based on existing elements in XAML?
On a side note, you'd also not inherit from a Control to change its looks. That is done entirely in XAML. Inheritance should generally be about changing a Controls behaviour (events it raises, when it raises them, how it interacts with its ControlTemplate, etc). Nothing else.
After thinking a little bit about how XAML works and what kind of functionality I would like to add in apps in the future, is it possible to "update" XAML code just like javascript updates HTML or is another mechanism usually used here? An example where you might use this: If a user clicks on a new Button and a new textbox must be inserted in the current page, you can of course instantiate the new Textbox in your C# code and add it as a children to the container. But XAML is used to create such content much more easily so how would you got about adding XAML code dynamically while also knowing that XAML code is actually compiled to C#? Is there like a function which you can use to inject XAML code from a C# script?
There are many ways to do this. Some examples:
a)
One way is similar to what you're familiar with. In that scenario you create your Controls in code-behind and insert them into the visual tree (what XAML is turned into at runtime). This works fine for small changes to the UI.
b)
Another way is to include all the Controls you need in the XAML, but set their Visibility to collapsed, so they are invisible to the user. When required you'd then just set their Visibility to visible to have them shown. This is easy and performs well, but it only works for a set number of elements. It's not really as dynamic as what you're likely asking for.
c)
The final and most common approach involves the MVVM pattern. This is a bit more involved to explain and understand, but it essentially allows the dynamic parts of your UI to be constructed automatically based on the contents of your business model.
Imagine having three Person objects that are contained in an ObservableCollection, and that collection being observed by a ListView Control that you define in XAML. Together with that ListView you'd also use XAML to define a DataTemplate that specifies how a Person object is to be shown on screen. After hooking all that up, you can then add/remove Person objects to/from the ObservableCollection and the ListView will update itself automatically based on the collection's contents.
With this solution you have no code explicitly creating the dynamic parts of the UI at all.
There are many samples on msdn that you can look at that demonstrate this type of thing, for example here:
https://code.msdn.microsoft.com/wind...fc27dd#content- Share
- Share this post on
Digg
Del.icio.us
Technorati
Twitter
Stamper_wc likes this.02-21-2015 11:46 AMLike 1 - Share
- Wow that is an detailed explanation, thanks so much! I am definitely going to have a look at those examples. Thanks again!
- Share
- Share this post on
Digg
Del.icio.us
Technorati
Twitter
a5cent likes this.02-21-2015 11:50 AMLike 1 - Share
- Forum
- Developers
- Developers Corner
Q's about Windows Phone 8 App dev; Working through the Bob's, Clint's and Larry's tutorial
« [Request] Devs to Pickup Abandoned Game
|
How does MSFT attract Android and iOS developers to W10? »
Similar Threads
-
Is Windows 10 For Phone Supports Background Download? ?
By sanjeet_deshwal in forum Windows Insider ProgramReplies: 1Last Post: 02-21-2015, 01:42 PM -
Where is the Windows Phone Taskbar???
By Windows Central Question in forum Ask a QuestionReplies: 2Last Post: 02-21-2015, 08:12 AM -
Why has my Nokia 735 screen rotation stopped working?
By Windows Central Question in forum Ask a QuestionReplies: 1Last Post: 02-21-2015, 07:10 AM -
Is there a way to share mp3 via Whatsapp - Windows 7 phone?
By kgb714 in forum Other Operating SystemsReplies: 2Last Post: 02-21-2015, 07:03 AM -
Is every lumia getting windows phone 10 upgrade?
By Priyanka Goswami in forum Ask a QuestionReplies: 4Last Post: 02-21-2015, 06:30 AM
LINK TO POST COPIED TO CLIPBOARD