SHARE
TWEET

MainPage de Settings Charm

elGuille Jan 14th, 2013 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports Windows.UI.ApplicationSettings
  2. Imports Windows.UI.Core
  3.  
  4. ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  5.  
  6. ''' <summary>
  7. ''' An empty page that can be used on its own or navigated to within a Frame.
  8. ''' </summary>
  9. Public NotInheritable Class MainPage
  10.     Inherits Page
  11.  
  12.     ''' <summary>
  13.     ''' Invoked when this page is about to be displayed in a Frame.
  14.     ''' </summary>
  15.     ''' <param name="e">Event data that describes how this page was reached.  The Parameter
  16.     ''' property is typically used to configure the page.</param>
  17.     Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
  18.  
  19.     End Sub
  20.  
  21.     Public Sub New()
  22.  
  23.         ' This call is required by the designer.
  24.         InitializeComponent()
  25.  
  26.         ' Add any initialization after the InitializeComponent() call.
  27.  
  28.         inicializarPopup()
  29.  
  30.     End Sub
  31.  
  32. #Region " Todo lo relacionado con el panel de configuración Settings Charm "
  33.  
  34.     ' Para el panel de configuración
  35.     Dim _windowBounds As Rect
  36.     Dim _settingsWidth As Double = 346 '346 el 646 es demasiado ancho y el 343 es el tamaño normal
  37.     Dim _settingsPopup As Popup
  38.  
  39.     ''' <summary>
  40.     ''' Asignaciones para usar el panel de configuración
  41.     ''' Estas declaraciones estaba en el constructor
  42.     ''' </summary>
  43.     Private Sub inicializarPopup()
  44.         _windowBounds = Window.Current.Bounds
  45.  
  46.         AddHandler Window.Current.SizeChanged, AddressOf OnWindowSizeChanged
  47.         AddHandler SettingsPane.GetForCurrentView().CommandsRequested, AddressOf startPage_CommandsRequested
  48.     End Sub
  49.  
  50.     Private Sub OnWindowSizeChanged(sender As Object, e As WindowSizeChangedEventArgs)
  51.         _windowBounds = Window.Current.Bounds
  52.     End Sub
  53.  
  54.     Private Sub startPage_CommandsRequested(sender As SettingsPane, args As SettingsPaneCommandsRequestedEventArgs)
  55.  
  56.         Dim sOpciones As String = "Preferencias"
  57.  
  58.         ' Comprobar que no estén ya añadidos los comandos
  59.         Dim yaEsta As Boolean = False
  60.  
  61.         For Each c In args.Request.ApplicationCommands
  62.             If c.Label = sOpciones Then
  63.                 yaEsta = True
  64.                 Exit For
  65.             End If
  66.         Next
  67.         If yaEsta Then
  68.             args.Request.ApplicationCommands.Clear()
  69.         End If
  70.  
  71.         Dim cmd As New SettingsCommand(
  72.                 "lasPreferencias", sOpciones,
  73.                 Sub()
  74.                     _settingsPopup = New Popup()
  75.                     AddHandler _settingsPopup.Closed, AddressOf OnPopupOpcionesClosed
  76.                     AddHandler Window.Current.Activated, AddressOf OnWindowActivated
  77.                     _settingsPopup.IsLightDismissEnabled = True
  78.                     _settingsPopup.Width = _settingsWidth
  79.                     _settingsPopup.Height = _windowBounds.Height
  80.  
  81.                     Dim mypane As New Settings
  82.  
  83.                     mypane.Titulo = sOpciones
  84.  
  85.                     mypane.Width = _settingsWidth
  86.                     mypane.Height = _windowBounds.Height
  87.  
  88.                     _settingsPopup.Child = mypane
  89.                     _settingsPopup.SetValue(Canvas.LeftProperty, _windowBounds.Width - _settingsWidth)
  90.                     _settingsPopup.SetValue(Canvas.TopProperty, 0)
  91.                     _settingsPopup.IsOpen = True
  92.  
  93.                 End Sub)
  94.  
  95.         args.Request.ApplicationCommands.Add(cmd)
  96.  
  97.         'Dim cmdAyuda As New SettingsCommand("clockAyuda", sAyuda,
  98.         '                                    Sub()
  99.         '                                        ' Sólo queremos mostrar otra página  (18/Dic/12)
  100.         '                                        ' (pero no dentro del panel de configuración)
  101.         '                                        mostrarAyuda()
  102.         '                                    End Sub)
  103.  
  104.         'args.Request.ApplicationCommands.Add(cmdAyuda)
  105.  
  106.     End Sub
  107.  
  108.     Private Sub OnWindowActivated(sender As Object, e As WindowActivatedEventArgs)
  109.         If e.WindowActivationState = CoreWindowActivationState.Deactivated Then
  110.             _settingsPopup.IsOpen = False
  111.         End If
  112.     End Sub
  113.  
  114.     Private Sub OnPopupOpcionesClosed(sender As Object, e As Object)
  115.         Dim settingsPanel As Settings
  116.         settingsPanel = TryCast(TryCast(sender, Popup).Child, Settings)
  117.  
  118.         RemoveHandler Window.Current.Activated, AddressOf OnWindowActivated
  119.     End Sub
  120.  
  121.     Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
  122.         SettingsPane.Show()
  123.     End Sub
  124.  
  125.     Private Sub HandleSizeChange(sender As Object, e As RoutedEventArgs)
  126.         Dim rb As RadioButton = TryCast(sender, RadioButton)
  127.         _settingsWidth = Convert.ToInt32(rb.Content)
  128.  
  129.     End Sub
  130.  
  131.  
  132.  
  133. #End Region
  134.  
  135. End Class
RAW Paste Data
Pastebin PRO Autumn Special!
Get 40% OFF on Pastebin PRO accounts!
Top