Showing posts with label Windows Store App. Show all posts
Showing posts with label Windows Store App. Show all posts

Wednesday, June 5, 2013

GridView Scroll to a desired group in a Windows Store App

By default, in a Windows Store App, the focus in a GridView is given to the element "0" of the group "0". But what if you wanto to change this behaviour and make it "open" to another element?

To do it, you have to manage the  itemGridView_Loaded event and use the CollectionView:

In XAML:
<GridView
    x:Name="itemGridView"
    AutomationProperties.AutomationId="ItemGridView"
    AutomationProperties.Name="Grouped Items"
    Grid.RowSpan="2"
    Padding="116,137,40,46"
    ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
    ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
    SelectionMode="None"
    IsSwipeEnabled="false"
    IsItemClickEnabled="True"
    ItemClick="ItemView_ItemClick"
    Loaded="itemGridView_Loaded">

Incode-behind:
private bool firstTime = true;
        
   private void itemGridView_Loaded(object sender, RoutedEventArgs e)
   {
        ICollectionView view;
        ICollectionViewGroup myGroup;
        Data.MyDataType myItem;
 
        if (!this.firstTime) return; else firstTime = false;
        view = itemGridView.ItemsSource as ICollectionView;
        view.CurrentChanged += view_CurrentChanged;
        int groupIndex = 2; // an integer value between 0 and # of items in the groups collection
        myGroup = view.CollectionGroups[groupIndex] as ICollectionViewGroup;
        myItem = recipeGroup.GroupItems[0] as Data.MyDataType;
        view.MoveCurrentTo(myItem);
    }
     
    private void view_CurrentChanged(object sender, object e)
    {
        ICollectionView view;
        Data.MyDataType  myItem;
         
        view = itemGridView.ItemsSource as ICollectionView;
        view.CurrentChanged -= view_CurrentChanged;
        myItem = view.CurrentItem as Data.MyDataType;
        itemGridView.ScrollIntoView(view.CurrentItem, ScrollIntoViewAlignment.Leading);
    }

Wednesday, May 29, 2013

Privacy Policy in Charm Bar: the easiest way

When you make a Windows Store App, if it uses any Network connection, you have to specify your Privacy Settings in both Store page and Charm Bar.

But how to do it? What's the simplest way?

So, here's the answers.

Do the following in your App.xaml.cs:

1) Add the namespaces
using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;


2) Add the handler during app initialization (into OnLaunched())
SettingsPane.GetForCurrentView().CommandsRequested += SettingCharmManager_CommandsRequested;


3) Add my handler that shows the privacy text
private void SettingCharmManager_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{

    args.Request.ApplicationCommands.Add(new SettingsCommand("privacypolicy", "Privacy policy", OpenPrivacyPolicy));

}

4) Add OpenPrivacyPolicy method
private async void OpenPrivacyPolicy(IUICommand command)

{

    Uri uri = new Uri("http://my_website/my_privacy.html");
    await Windows.System.Launcher.LaunchUriAsync(uri);

}