locked
Semantic zoom - disable automatic selection of item

    Question

  • Everytime when I launch my app it appears to automatically select an item for me. Does anyone know why this is happening and how it can be resolved?

    XAML

                <SemanticZoom x:Name="semanticZoom" Margin="0,0,0,0">
                    <SemanticZoom.ZoomedOutView>
                        <GridView ScrollViewer.IsHorizontalScrollChainingEnabled="False" >
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Group.Key}" HorizontalAlignment="Center" FontFamily="Segoe UI" FontWeight="Light" FontSize="56" Foreground="White"/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
                            <GridView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <ItemsWrapGrid ItemWidth="200" ItemHeight="200" MaximumRowsOrColumns="4" VerticalAlignment="Center"/>
                                </ItemsPanelTemplate>
                            </GridView.ItemsPanel>
                            <GridView.ItemContainerStyle>
                                <Style TargetType="GridViewItem">
                                    <Setter Property="Margin" Value="4" />
                                    <Setter Property="Padding" Value="10" />
                                    <Setter Property="Background" Value="#9B0056" />
                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                                    <Setter Property="VerticalContentAlignment" Value="Center" />
                                </Style>
                            </GridView.ItemContainerStyle>
                        </GridView>
                    </SemanticZoom.ZoomedOutView>
                    <SemanticZoom.ZoomedInView>
                        <GridView x:Name="ItemsGridView"
                                  ItemsSource="{Binding Source={StaticResource cvs2}}" 
                                  ShowsScrollingPlaceholders="False"
                                  ContainerContentChanging="ItemsGridView_ContainerContentChanging"
                                  IsSwipeEnabled="True" ScrollViewer.IsHorizontalScrollChainingEnabled="False">
                            <GridView.ItemTemplate>
                                <DataTemplate>
                                    <local:ItemViewer/>
                                </DataTemplate>
                            </GridView.ItemTemplate>
    
                            <GridView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <ItemsWrapGrid/>
                                </ItemsPanelTemplate>
                            </GridView.ItemsPanel>
    
                            <GridView.GroupStyle>
                                <GroupStyle>
                                    <GroupStyle.HeaderTemplate>
                                        <DataTemplate>
                                            <TextBlock Text='{Binding Key}' Foreground="#FF9B0056" Margin="5" FontSize="50" FontFamily="Segoe UI" FontWeight="Light" />
                                        </DataTemplate>
                                    </GroupStyle.HeaderTemplate>
                                </GroupStyle>
                            </GridView.GroupStyle>
                        </GridView>
                    </SemanticZoom.ZoomedInView>
                </SemanticZoom>
    

    C# (DataSource.cs)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Exits_Expert_London_Lite
    {
        using System;
        using Windows.UI.Xaml.Data;
        using Windows.UI.Xaml.Media;
    
        // To significantly reduce the sample data footprint in your production application, you can set
        // the DISABLE_SAMPLE_DATA conditional compilation constant and disable sample data at runtime.
    #if DISABLE_SAMPLE_DATA
    	internal class SampleDataSource { }
    #else
    
        public class Item : System.ComponentModel.INotifyPropertyChanged
        {
            public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    
            protected virtual void OnPropertyChanged(string propertyName)
            {
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
                }
            }
    
            private string _Station = string.Empty;
            public string Station
            {
                get
                {
                    return this._Station;
                }
    
                set
                {
                    if (this._Station != value)
                    {
                        this._Station = value;
                        this.OnPropertyChanged("Station");
                    }
                }
            }
    
            private string _Zone = string.Empty;
            public string Zone
            {
                get
                {
                    return this._Zone;
                }
    
                set
                {
                    if (this._Zone != value)
                    {
                        this._Zone = value;
                        this.OnPropertyChanged("Zone");
                    }
                }
            }
    
            private string _Link = string.Empty;
            public string Link
            {
                get
                {
                    return this._Link;
                }
    
                set
                {
                    if (this._Link != value)
                    {
                        this._Link = value;
                        this.OnPropertyChanged("Link");
                    }
                }
            }
        }
    
        public class GroupInfoList<T> : List<object>
        {
    
            public object Key { get; set; }
    
    
            public new IEnumerator<object> GetEnumerator()
            {
                return (System.Collections.Generic.IEnumerator<object>)base.GetEnumerator();
            }
        }
    
    
        public class StoreData
        {
            public StoreData()
            {
                Item item;
    
                item = new Item();
                item.Station = "Aldgate";
                item.Link = "/Lines and Stations/Metropolitan/Aldgate_(Metropolitan).xaml";
                Collection.Add(item);
    
            }
    
    
    
            private ItemCollection _Collection = new ItemCollection();
    
            public ItemCollection Collection
            {
                get
                {
                    return this._Collection;
                }
            }
    
            internal List<GroupInfoList<object>> GetGroupsByCategory()
            {
                List<GroupInfoList<object>> groups = new List<GroupInfoList<object>>();
    
                var query = from item in Collection
                            orderby ((Item)item).Zone
                            group item by ((Item)item).Zone into g
                            select new { GroupName = g.Key, Items = g };
                foreach (var g in query)
                {
                    GroupInfoList<object> info = new GroupInfoList<object>();
                    info.Key = g.GroupName;
                    foreach (var item in g.Items)
                    {
                        info.Add(item);
                    }
                    groups.Add(info);
                }
    
                return groups;
            }
    
            internal List<GroupInfoList<object>> GetGroupsByLetter()
            {
                List<GroupInfoList<object>> groups = new List<GroupInfoList<object>>();
    
                var query = from item in Collection
                            orderby ((Item)item).Station
                            group item by ((Item)item).Station[0] into g
                            select new { GroupName = g.Key, Items = g };
                foreach (var g in query)
                {
                    GroupInfoList<object> info = new GroupInfoList<object>();
                    info.Key = g.GroupName;
                    foreach (var item in g.Items)
                    {
                        info.Add(item);
                    }
                    groups.Add(info);
                }
    
                return groups;
    
            }
        }
    
        // Workaround: data binding works best with an enumeration of objects that does not implement IList
        public class ItemCollection : IEnumerable<Object>
        {
            private System.Collections.ObjectModel.ObservableCollection<Item> itemCollection = new System.Collections.ObjectModel.ObservableCollection<Item>();
    
            public IEnumerator<Object> GetEnumerator()
            {
                return itemCollection.GetEnumerator();
            }
    
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
    
            public void Add(Item item)
            {
                itemCollection.Add(item);
            }
        }
    
    #endif
    }
    

    Sunday, February 15, 2015 10:50 PM

Answers

  • Hi findlay93,

    It set the first item in GridView as the default selected item. Add the following code snippet to your project can unselect it after you binding data source to control.

    (semanticZoom.ZoomedInView as ListViewBase).SelectedIndex = -1;

    Try it and let me know the result.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by m.findlay93 Wednesday, February 18, 2015 4:43 PM
    Tuesday, February 17, 2015 6:55 AM
    Moderator
  • I used the following sample to test. https://code.msdn.microsoft.com/GroupedGridView-77c59e8e. Add the code snippet to the last line of Scenario3 constructor method.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by m.findlay93 Wednesday, February 18, 2015 4:43 PM
    Wednesday, February 18, 2015 1:40 AM
    Moderator

All replies

  • try msdn code sample, does it happen again?
    Monday, February 16, 2015 10:51 PM
  • Hi findlay93,

    It set the first item in GridView as the default selected item. Add the following code snippet to your project can unselect it after you binding data source to control.

    (semanticZoom.ZoomedInView as ListViewBase).SelectedIndex = -1;

    Try it and let me know the result.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by m.findlay93 Wednesday, February 18, 2015 4:43 PM
    Tuesday, February 17, 2015 6:55 AM
    Moderator
  • Where within my C# code does this need to go?
    Tuesday, February 17, 2015 3:28 PM
  • I used the following sample to test. https://code.msdn.microsoft.com/GroupedGridView-77c59e8e. Add the code snippet to the last line of Scenario3 constructor method.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by m.findlay93 Wednesday, February 18, 2015 4:43 PM
    Wednesday, February 18, 2015 1:40 AM
    Moderator
  • Brilliant! Problem solved.
    Wednesday, February 18, 2015 4:42 PM