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

  • Home
  • SEARCH
  • 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 7519235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:52:08+00:00 2026-05-30T01:52:08+00:00

I have a ListBox in a popup. It’s bound to a simple Dictionary. I

  • 0

I have a ListBox in a popup. It’s bound to a simple Dictionary. I also have a ItemContainerStyle to theme listbox highlights. If I add ListBoxItems at design time, the selection style works, but the same style does not work when I assign ItemsSource. To troubleshoot I stripped it to barebones, and problem persists. Below is the code I have, Launch it, and click on ShowPopup to open Popup, first you will see items added in design time, and if you click on “Add ItemsSource” it will show run time items. You can see the selection in design time items, and not in run time items. (items generated via itemssource).

Any ideas? What am I missing?

<phone:PhoneApplicationPage   
    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:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"    
    x:Class="ObservableListSample.MainPage"  
    mc:Ignorable="d" d:DesignWidth="728" d:DesignHeight="480"  
    FontFamily="{StaticResource PhoneFontFamilyNormal}"  
    FontSize="{StaticResource PhoneFontSizeNormal}"  
    Foreground="{StaticResource PhoneForegroundBrush}"  
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"  
    shell:SystemTray.IsVisible="True"    
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit">   

    <!--LayoutRoot is the root grid where all page content is placed-->  
    <Grid x:Name="LayoutRoot" Background="Transparent">   
        <!--ContentPanel - place additional content here-->  
        <Grid x:Name="ContentPanel" Margin="12,0,12,0">   
            <controls:Pivot Margin="8" Title="pivot">   
                <controls:PivotItem Margin="12" Header="Popup">   
                    <Grid Margin="12">   
                        <Button Content="Show Popup" Margin="1,0,0,0" VerticalAlignment="Bottom" Click="Button_Click"/>   
                    </Grid>  
                </controls:PivotItem>  
            </controls:Pivot>  
            <Popup x:Name="LocPopup"  
                   Margin="12,120,12,12">   
                <StackPanel Background="{StaticResource PhoneBackgroundBrush}"  
                            Height="610"  
                            Width="432">   
                    <Button   
                               Content="Add ItemsSource"  
                                Click="Button_Click"  
                               VerticalAlignment="Top" Margin="12" />  
                    <ListBox x:Name="LibraryLocations" Height="480">   
                        <ListBox.Resources>    <DataTemplate x:Key="DataTemplate1">   
                                <ListBoxItem Content="{Binding Value}" Tag="{Binding Key.Name}"/>   
                            </DataTemplate>  
                        </ListBox.Resources>  
                        <ListBox.ItemTemplate>  
                            <StaticResource ResourceKey="DataTemplate1"/>   
                        </ListBox.ItemTemplate>  
                        <ListBoxItem Content="ListBoxItem 1" />  
                        <ListBoxItem Content="ListBoxItem 2" />  
                        <ListBoxItem Content="ListBoxItem 3" />  
                        <ListBoxItem Content="ListBoxItem 4" />  
                        <ListBoxItem Content="ListBoxItem 5" />  
                        <ListBoxItem Content="ListBoxItem 6" />  
                    </ListBox>  
                </StackPanel>  
            </Popup>  
        </Grid>  
    </Grid>  
</phone:PhoneApplicationPage>  

C#

using System;   
using System.Collections.Generic;   
using System.Linq;   
using System.Net;   
using System.Windows;   
using System.Windows.Controls;   
using System.Windows.Documents;   
using System.Windows.Input;   
using System.Windows.Media;   
using System.Windows.Media.Animation;   
using System.Windows.Shapes;   
using Microsoft.Phone.Controls;   
using System.Collections.ObjectModel;   

namespace ObservableListSample   
{   

    public partial class MainPage : PhoneApplicationPage   
    {   
         // Constructor   
        public MainPage()   
        {   
            InitializeComponent();   
        }   

        private void Button_Click(object sender, RoutedEventArgs e)   
        {   
            if (!LocPopup.IsOpen)   
                LocPopup.IsOpen = true;   
            else  
            {   
                Dictionary<string, string> items = new Dictionary<string, string>();   
                for (int i = 0; i < 20; i++)   
                {   
                    items.Add(i.ToString(), "Item " + i.ToString());   
                }   
                if (LibraryLocations.ItemsSource == null)   
                    LibraryLocations.Items.Clear();   
                LibraryLocations.ItemsSource = items;   
            }   
        }   

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)   
        {   
            if (LocPopup.IsOpen)   
            {   
                LocPopup.IsOpen = false;   
                e.Cancel = true;   
            }   
            else  
            {   
                base.OnBackKeyPress(e);   
            }   
        }   

    }     

}  
  • 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-30T01:52:09+00:00Added an answer on May 30, 2026 at 1:52 am

    I don’t see any ItemContainerStyle in your sample. Do you really need using ListBoxItem in the ListBox.ItemTemplate? Try this one instead:

    <DataTemplate x:Key="DataTemplate1">
       <TextBlock Text="{Binding Value}" Tag="{Binding Key.Name}"/>
    </DataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox which is bound to a collection. When I add an
I have ListBox called lstProductGroups. On a simple Windows Form, a method called GetGroups
I have a ListBox bound to a list of Items (for arguement, lets say
I have a listbox that users can add/remove from. To add, there's a text
I have a ListBox in a PopupControl . Problem is that while scrolling, Popup
I need to have selection changed event inside a listbox itemtemplate. My listbox consists
I have a Listbox which I add items to it in the OnClick event.
I have a WPF Popup control with a ListBox and a Button in it.
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a listbox which is bound to a CollectionViewSource (backed by an ObservableCollection).

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.