Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:44:25+00:00 2026-05-30T03:44:25+00:00

I have a Menu object (set as the DataContext) which contains many Options (Menu.Options)

  • 0

I have a Menu object (set as the DataContext) which contains many Options (Menu.Options), which contains a Name (Option.Name) and many Options (Option.Options). The collections are all of type ObservableCollection<T>.

The Menu is loaded from an XML file, so the amount of Options and Values can vary.

To help visualise, here is the relevant XAML:

<ListBox ItemsSource="{Binding Path=Options}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <!-- Title -->
                <TextBlock Text="{Binding Path=Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                <!-- Selection -->
                <toolkit:ListPicker ItemsSource="{Binding Path=Options}" SelectionChanged="ListPicker_SelectionChanged">
                    <toolkit:ListPicker.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Name}" />
                        </DataTemplate>
                    </toolkit:ListPicker.ItemTemplate>
                    <toolkit:ListPicker.FullModeItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Name}" />
                        </DataTemplate>
                    </toolkit:ListPicker.FullModeItemTemplate>
                </toolkit:ListPicker>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

I have a method ListPicker_SelectionChanged on the SelectionChanged event, in which I want to somehow mark the current selection in the databound model. I need to do it using just the parameters supplied to the method, as each ListPicker is generated at runtime. So I can’t be specifying actual control names (as far as I’m aware anyway).

I can see two possible options:

1) To have a CurrentSelection inside Menu.Option, where I can put a reference to the last selected item for that ListPicker

2) To have a Selected attribute on the Option.Option. Downside here though is making sure all elements are deselected when a new one is selected.

I’ve tried browsing the object tree of sender, but anything I find, such as ItemsHost, is inaccessible (private/protected).

Is there any way I can achieve a solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:44:26+00:00Added an answer on May 30, 2026 at 3:44 am

    Option 1 is the better one, use TwoWay binding on the ListPicker.SelectedItem.

    <phone:PhoneApplicationPage 
        x:Class="StackOverflowWP7.SO9369491"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        xmlns:local="clr-namespace:StackOverflowWP7.SO9369491_"
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True">
        <phone:PhoneApplicationPage.DataContext>
            <local:Menu>
                <local:Menu.Options>
                    <local:Option Description="Size">
                        <local:Option.Options>
                            <local:Option local:Description="Large" />
                            <local:Option local:Description="Regular" />
                        </local:Option.Options>
                        <local:Option.CurrentSelection>
                            <local:Option local:Description="Regular" />
                        </local:Option.CurrentSelection>
                    </local:Option>
                </local:Menu.Options>
            </local:Menu>
        </phone:PhoneApplicationPage.DataContext>
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!--TitlePanel contains the name of the application and page title-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <ListBox ItemsSource="{Binding Path=Options}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <!-- Title -->
                                <TextBlock Text="{Binding Path=Description}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                                <!-- Selection -->
                                <toolkit:ListPicker ItemsSource="{Binding Path=Options}"
                                                    SelectedItem="{Binding CurrentSelection, Mode=TwoWay}" >
                                    <toolkit:ListPicker.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Path=Description}" />
                                        </DataTemplate>
                                    </toolkit:ListPicker.ItemTemplate>
                                    <toolkit:ListPicker.FullModeItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Path=Description}" />
                                        </DataTemplate>
                                    </toolkit:ListPicker.FullModeItemTemplate>
                                </toolkit:ListPicker>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </Grid>
    
    </phone:PhoneApplicationPage>
    

    Here’s the Code Behind

    namespace StackOverflowWP7
    {
        using Microsoft.Phone.Controls;
    
        public partial class SO9369491 : PhoneApplicationPage
        {
            // Constructor
            public SO9369491()
            {
                InitializeComponent();
    
            }
    
        }
    
    }
    
    namespace StackOverflowWP7.SO9369491_
    {
        using System.Collections.ObjectModel;
        using System.Linq;
    
        public class Menu : Option
        {
            public Menu()
                : base("Main Menu")
            {
            }
        }
    
        public class Option
        {
            public Option() {}
    
            public Option(string Name, params string[] choices)
            {
                this.Description = Name;
                foreach (var choice in choices)
                {
                    this._options.Add(new Option(choice));
                }
            }
    
            public string Description { get; set; }
    
            private ObservableCollection<Option> _options = new ObservableCollection<Option>();
            public ObservableCollection<Option> Options { get { return _options; } }
    
            private Option _CurrentSelection;
    
            public Option CurrentSelection
            {
                get { 
                    return _CurrentSelection; 
                }
                set
                {
                    if (_options.Contains(value))
                    {
                        _CurrentSelection = value;
                    }
                    else
                    {
                        _CurrentSelection = _options.FirstOrDefault((o) => o.Description == value.Description);
                    }
                }
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp:menu object which I set up to use a SiteMapDataSource but
I have a Restaurant object, which contains a Menu . The Menu contains MenuItems
i have menu structure like below, <ul> <li class=menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1406
Please clue this newb in. I've got a menu with it's object type set
I have an MVC masterpage set up which loads a dynamic menu using AJAX
i have menu structure like below <ul class=menu_bg id=menu-main-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-653
I have an associative array (object) of the following construction var menu = new
I have a menu running off of a sitemap which one of the SiteMapNode
I'm trying to set up a menu. Because this menu can have a varying
I have runtime-created menu based on words in selected gtkTreeView row. gboolean menu_RELEASE(GtkObject *object,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.