Before reading this article, I highly recommend reading the following article:
Why ContentDialog in XAML
When user want to create custom based modal dialog, compare to code behind page (part1), XAML is best and fastest way to create custom based ContentDialog.
Let us see how to create below custom dialog in XAML page.
Steps:
- Firstly, declare the ContentDialog class & name of content control must be declared.
- Overwrite the Title & Content template, Title add the Content.
Note: In step 1, Name of the content dialog must be declared, why? Invoking ContentDialog in XAML is not possible, it will invoke only in the code behind page, that’s the reason we give the name in the ContentDialog.
So far we have seen how to handle ContentDialog in XAML page.
Note: If this code is added into main project, it tightly coupled, so best practice is to create ContentDialog in the separate XAML page.
Separate XAML Page: No need to write the code in Base, Visual studio 2015 provides default template. The template base code will write automatically.
Now how to add this default template.
Right click, project item (goto Add, then NewItem),
Select the ContentDialog, then Add the item.
Note: Event handler automatically implemented for primary and secondary button.
Remove the Title property in this page because we are going to overwrite the Title template. (above code Title property removed).
Invoke this dialog into the main application.