PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/MetroAppBarSample/MainPage.xaml.cs

https://github.com/mbrit/MetroAppBarSample
C# | 58 lines | 45 code | 4 blank | 9 comment | 8 complexity | 3245f134e737eafe77938c6a12453454 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Xml.Linq;
  6. using Windows.Foundation;
  7. using Windows.Foundation.Collections;
  8. using Windows.UI.Xaml;
  9. using Windows.UI.Xaml.Controls;
  10. using Windows.UI.Xaml.Controls.Primitives;
  11. using Windows.UI.Xaml.Data;
  12. using Windows.UI.Xaml.Input;
  13. using Windows.UI.Xaml.Media;
  14. using Windows.UI.Xaml.Navigation;
  15. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  16. namespace MetroAppBarSample
  17. {
  18. /// <summary>
  19. /// An empty page that can be used on its own or navigated to within a Frame.
  20. /// </summary>
  21. public sealed partial class MainPage : Page
  22. {
  23. public MainPage()
  24. {
  25. this.InitializeComponent();
  26. }
  27. /// <summary>
  28. /// Invoked when this page is about to be displayed in a Frame.
  29. /// </summary>
  30. /// <param name="e">Event data that describes how this page was reached. The Parameter
  31. /// property is typically used to configure the page.</param>
  32. protected override void OnNavigatedTo(NavigationEventArgs e)
  33. {
  34. XNamespace p_ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
  35. XNamespace xaml_ns = "http://schemas.microsoft.com/winfx/2006/xaml";
  36. var doc = XDocument.Load(@"Common\StandardStyles.xaml");
  37. foreach (var style in doc.Descendants(p_ns + "Style"))
  38. {
  39. var key = style.Attribute(xaml_ns + "Key");
  40. if (key != null && key.Value != null)
  41. {
  42. var basedOn = style.Attribute("BasedOn");
  43. if (basedOn != null && basedOn.Value == @"{StaticResource AppBarButtonStyle}")
  44. {
  45. var button = new Button();
  46. button.Style = App.Current.Resources[key.Value] as Style;
  47. ToolTipService.SetToolTip(button, key.Value);
  48. AppBarButtonListView.Items.Add(button);
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }