martes, 16 de octubre de 2012

Charm de settings con la política de privacidad

Hola, Uno de los motivos por los cuales las app no son aceptadas en el windows store es por que no tienen definida una política de privacidad.

En el siguiente ejemplo voy a mostrar como crear en el charm de settings una política de privacidad.

1. Crear un xaml que contenga la información de “acerca de”

a. En nuestra app adicionar un nuevo control de usuario, en mi caso lo llamaré AcercaDe.xaml:

image

b. Escribir en este xaml la información de contacto y la información de la política de privacidad, para ello he creado en este xaml un stackpanel dentro del cual utilicé varios textblok para especificar la información:

<UserControl
x:Class="MiTaskList.AcercaDe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MiTaskList"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid Background="Black">
<StackPanel>
<TextBlock>Acerca de:</TextBlock>
<TextBlock>Aplicacion desarrollada por:</TextBlock>
<TextBlock>Robinson Moscoso</TextBlock>
<TextBlock>rmoscosp@hotmail.com</TextBlock>
<TextBlock>Tel: 57-3002141652</TextBlock>
<TextBlock>robinmp.wix.com</TextBlock>
<TextBlock></TextBlock>
<TextBlock>Política de privacidad</TextBlock>
<TextBlock TextWrapping="Wrap">Esta aplicación hace uso de la conexión a internet, única y exclusivamente, para descargar información relativa de la misma desde nuestros servidores. Ninguna información de la máquina o del usuario es enviada de vuelta a ellos ni a ningún otro servidor a través de internet ni de ningún otro medio por parte de esta aplicación.</TextBlock>

</StackPanel>

</Grid>
</UserControl>



2. Definir una variable en el app.xaml.cs que permita controlar que ya se registró el evento que publica el vinculo en el charm de settings.



image


3. Definir en la primera pagina que se ejecuta en mi app el evento que adiciona a settings el vinculo al xaml que he creado en el punto 1:



a. adicionar variables de control:


image


b. Adicionar en el constructor el registro del evento:


image


c. Adicionar el método OnCommandRequest:


image


d. Adicionar el método onSettingsCommand: (en este método relaciono el xaml de AcercaDe.xaml creado en el numeral 1 de este post)


image


e. agrego los métodos de OnWindowSizeChanged, OnWindowActivated y OnPopupClosed


image


f. todo el código debería verse asi:

using MiTaskList.DataModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace MiTaskList
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
public sealed partial class Inicio : MiTaskList.Common.LayoutAwarePage
{

// Used to determine the correct height to ensure our custom UI fills the screen.
private Rect windowBounds;

// Desired width for the settings UI. UI guidelines specify this should be 346 or 646 depending on your needs.
private double settingsWidth = 646;

// This is the container that will hold our custom content.
private Popup settingsPopup;


public Inicio()
{
this.InitializeComponent();

windowBounds = Window.Current.Bounds;

// Added to listen for events when the window size is updated.
Window.Current.SizeChanged += OnWindowSizeChanged;

//Evento de lanzamiento de settings
//rootPage.NotifyUser("Defaults command added", NotifyType.StatusMessage);
if (!App.isEventRegistered)
{
// Listening for this event lets the app initialize the settings commands and pause its UI until the user closes the pane.
// To ensure your settings are available at all times in your app, place your CommandsRequested handler in the overridden
// OnWindowCreated of App.xaml.cs
SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
App.isEventRegistered = true;
}


}

private void onCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs eventArgs)
{
UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);

SettingsCommand generalCommand = new SettingsCommand("DefaultsId", "Acerca de", handler);
eventArgs.Request.ApplicationCommands.Add(generalCommand);
}

private void onSettingsCommand(IUICommand command)
{
//rootPage.NotifyUser("Defaults command invoked", NotifyType.StatusMessage);

// Create a Popup window which will contain our flyout.
settingsPopup = new Popup();
settingsPopup.Closed += OnPopupClosed;
Window.Current.Activated += OnWindowActivated;
settingsPopup.IsLightDismissEnabled = true;
settingsPopup.Width = settingsWidth;
settingsPopup.Height = windowBounds.Height;

// Add the proper animation for the panel.
settingsPopup.ChildTransitions = new TransitionCollection();
settingsPopup.ChildTransitions.Add(new PaneThemeTransition()
{
Edge = (SettingsPane.Edge == SettingsEdgeLocation.Right) ?
EdgeTransitionLocation.Right :
EdgeTransitionLocation.Left
});

// Create a SettingsFlyout the same dimenssions as the Popup.
AcercaDe mypane = new AcercaDe();
mypane.Width = settingsWidth;
mypane.Height = windowBounds.Height;

// Place the SettingsFlyout inside our Popup window.
settingsPopup.Child = mypane;

// Let's define the location of our Popup.
settingsPopup.SetValue(Canvas.LeftProperty, SettingsPane.Edge == SettingsEdgeLocation.Right ? (windowBounds.Width - settingsWidth) : 0);
settingsPopup.SetValue(Canvas.TopProperty, 0);
settingsPopup.IsOpen = true;
}

void OnWindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
windowBounds = Window.Current.Bounds;
}

private void OnWindowActivated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
{
settingsPopup.IsOpen = false;
}
}

void OnPopupClosed(object sender, object e)
{
Window.Current.Activated -= OnWindowActivated;
}


/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
}

/// <summary>
/// Preserves state associated with this page in case the application is suspended or the
/// page is discarded from the navigation cache. Values must conform to the serialization
/// requirements of <see cref="SuspensionManager.SessionState"/>.
/// </summary>
/// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
protected override void SaveState(Dictionary<String, Object> pageState)
{
}

}
}

 


luego se ejecutar y al hacer clic en settings  se ve de esta forma:


image


y al hacer clic en acerca de, se abre el AcercaDe.xaml:


image

1 comentario:

  1. Amigo, problemas con el Acercade.xaml.cs me dice que no esta espeficicado.

    public Acercade()
    {
    this.InitializeComponent();
    }

    Que hago?

    ResponderEliminar