ContentDialog Via XAML In Universal Windows Program: Part 2

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.

xaml

Steps:

  1. Firstly, declare the ContentDialog class & name of content control must be declared.

    code

  2. Overwrite the Title & Content template, Title add the Content.

    code

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.

code

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),

newitem

Select the ContentDialog, then Add the item.

add

Note: Event handler automatically implemented for primary and secondary button.

code

Remove the Title property in this page because we are going to overwrite the Title template. (above code Title property removed).

code

Invoke this dialog into the main application.

code

Up Next
    Ebook Download
    View all
    Learn
    View all