BladeControl In UWP With XAML And C#

Before reading this article, please go through the following article -

  1. Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015
  2. How to add UWP ToolKit controls in Universal Application Development With XAML AND C#

The BladeControl provides a container to host blades as extra detail pages in (for example) a master-detail scenario. The control is based on how the Azure Portal works.

Reading this article, you can learn how to use UWP Tool Kit Control – BladeControl in Universal Windows apps development with XAML and Visual C#.

The following important tools are required for developing UWP app.

  1. Windows 10 (Recommended).
  2. Visual Studio 2015 Community Edition (It is a free software available online).

Now, we can discuss the step by step process of app development.

Step 1 - Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C# ->Windows) -> Blank App -> Give it a suitable name ( UWPBlade ) -> OK.



Step 2 - Choose the Target and Minimum platform version that your Windows Universal Application will support. After this, the project creates App.xaml and MainPage.xaml.



For adding UWPToolKit Control, please refer - 

  1. How to add UWP ToolKit controls in Universal Application Development With XAML AND C#

Step 3 - Add TextBlock control and change the name and text property for title.



Step 4 - Add UWP Toolkit namespace in MainPage.xaml

xmlns:Controls="using:Microsoft.Toolkit.Uwp.UI.Controls"

Add the BladeControl from UWP Tool Kit and set the name properties.



Step 5 - Add the code inside BladeControl in MainPage.xaml for adding blades.

<Controls:BladeControl.Blades>
</Controls:BladeControl.Blades>


Add a blade and set the following properties – Name, BladeId, IsOpen, TitleBarVisibility.



Similarly, add 3 blades and set properties with relevant options.

  1. First blade is default blade.

    <Controls:Blade x:Name="BTest1" BladeId="BTest1" IsOpen="False" CloseButtonForeground="{x:Null}" Title="Default Blade">



  2. The second blade is custom titlebar colors.

    <Controls:Blade x:Name="BTest2" BladeId="BTest2" TitleBarBackground="Red" TitleBarForeground="Black" Title="Custom Title Bar colors">



  3. The third blade is custom Close button color.

    <Controls:Blade x:Name="BTest3" BladeId="BTest3" CloseButtonBackground="Black" CloseButtonForeground="White" Title="Custom Close Button Color">


Step 6 - Add blade element as stackpanel in common blade.



Add buttons for each blade.





Step 7 - Add TextBloack for each blade for displaying the content.



Note - Automatically, the following code will be generated in XAML Code View when we are done in the Design View.

  1. <Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  2. xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"  
  3. xmlns: local = "using:UWPBlade"  
  4. xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"  
  5. xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"  
  6. xmlns: Controls = "using:Microsoft.Toolkit.Uwp.UI.Controls"  
  7. x: Class = "UWPBlade.MainPage"  
  8. mc: Ignorable = "d" >  
  9.     <  
  10.     Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}" >  
  11.     <  
  12.     TextBlock x: Name = "tblTitle"  
  13. HorizontalAlignment = "Left"  
  14. Margin = "500,45,0,0"  
  15. TextWrapping = "Wrap"  
  16. Text = "UWP Tool Kit Blade Control "  
  17. VerticalAlignment = "Top"  
  18. Height = "30"  
  19. Width = "287"  
  20. FontWeight = "Bold"  
  21. FontSize = "22" / >  
  22.     <  
  23.     Controls: BladeControl x: Name = "BCtset"  
  24. HorizontalAlignment = "Stretch"  
  25. VerticalAlignment = "Stretch"  
  26. Margin = "10,80,0,112" >  
  27.     <  
  28.     Controls: BladeControl.Blades >  
  29.     <  
  30.     Controls: Blade x: Name = "BDCommon"  
  31. BladeId = "BDCommon"  
  32. IsOpen = "True"  
  33. TitleBarVisibility = "Collapsed" >  
  34.     <  
  35.     Controls: Blade.Element >  
  36.     <  
  37.     StackPanel x: Name = "SPCom"  
  38. Margin = "8,8,8,48" >  
  39.     <  
  40.     Button x: Name = "btnDefbla"  
  41. Width = "188"  
  42. Height = "41"  
  43. Margin = "0, 20, 0, 0"  
  44. Controls: BladeControl.ToggleBlade = "BTest1"  
  45. Content = "Default Blade" / >  
  46.     <  
  47.     Button x: Name = "btnblTitle"  
  48. Width = "188"  
  49. Height = "33"  
  50. Margin = "0,20,0,0"  
  51. Controls: BladeControl.ToggleBlade = "BTest2"  
  52. Content = "Blade with Title Bar" / >  
  53.     <  
  54.     Button x: Name = "btnblclose"  
  55. Width = "188"  
  56. Height = "39"  
  57. Margin = "0,20,0,0"  
  58. Controls: BladeControl.ToggleBlade = "BTest3"  
  59. Content = "Blade with Close Button" / >  
  60.     <  
  61.     /StackPanel> <  
  62.     /Controls:Blade.Element> <  
  63.     /Controls:Blade> <  
  64.     Controls: Blade x: Name = "BTest1"  
  65. BladeId = "BTest1"  
  66. IsOpen = "False"  
  67. CloseButtonForeground = "{x:Null}"  
  68. Title = "Default Blade" >  
  69.     <  
  70.     Controls: Blade.Element >  
  71.     <  
  72.     TextBlock HorizontalAlignment = "Center"  
  73. Text = "CSharp Corner - This is a Default Blade."  
  74. VerticalAlignment = "Center" / >  
  75.     <  
  76.     /Controls:Blade.Element> <  
  77.     /Controls:Blade> <  
  78.     Controls: Blade x: Name = "BTest2"  
  79. BladeId = "BTest2"  
  80. TitleBarBackground = "Red"  
  81. TitleBarForeground = "Black"  
  82. Title = "Custom Title Bar colors" >  
  83.     <  
  84.     Controls: Blade.Element >  
  85.     <  
  86.     TextBlock HorizontalAlignment = "Center"  
  87. Text = "CSharp Corner - This is a blade with custom titlebar colors."  
  88. VerticalAlignment = "Center" / >  
  89.     <  
  90.     /Controls:Blade.Element> <  
  91.     /Controls:Blade> <  
  92.     Controls: Blade x: Name = "BTest3"  
  93. BladeId = "BTest3"  
  94. CloseButtonBackground = "Black"  
  95. CloseButtonForeground = "White"  
  96. Title = "Custom Close Button Color" >  
  97.     <  
  98.     Controls: Blade.Element >  
  99.     <  
  100.     TextBlock HorizontalAlignment = "Center"  
  101. Text = "CSharp Corner - This is a blade with custom Close button Color."  
  102. VerticalAlignment = "Center" / >  
  103.     <  
  104.     /Controls:Blade.Element> <  
  105.     /Controls:Blade> <  
  106.     /Controls:BladeControl.Blades> <  
  107.     /Controls:BladeControl> <  
  108.     /Grid> <  
  109.     /Page>  
Step 8 - Deploy your app in Local Machine. 


The output of the UWPBlade app is shown below. 



Click the "Default Blade" button.



Click the "Blade with Title Bar" button. 


Click the "Blade with Close Button" button.
 


Summary - Now, you have successfully tested the UWP Tool Kit – BladeControl in Visual C# - UWP environment.