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 6629461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:15:49+00:00 2026-05-25T22:15:49+00:00

I have a need to use two listboxes, each bound to a different collection.

  • 0

I have a need to use two listboxes, each bound to a different collection.

i originally had this working with one listbox and binding before the need to bind two came up.
Here is how I was doing that.

 <Window x:Class="TeamManager.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc ="clr-namespace:TeamManager"
    Title="Game Manager" Height="800" Width="800">

<Window.Resources>
    <DataTemplate DataType="{x:Type loc:Game}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Name="dateBlock" Grid.Column="0" Grid.Row="1" Text="{Binding Date,  StringFormat=d}"></TextBlock>
            <TextBlock Name="TimeBlock" Grid.Column="1" Grid.Row="1" Text="{Binding Time}"></TextBlock>
            <Button Grid.Row="1" Grid.Column="2" CommandParameter="{Binding Id}" Click="Manage_Click" >Manage</Button>
            <Button Grid.Row="1" Grid.Column="3" CommandParameter="{Binding Id}" Click="Delete_Click" Height="16" Width="16">
                <Image Source="/Images/DeleteRed.png"></Image>

            </Button>
        </Grid>
    </DataTemplate>
</Window.Resources>
<StackPanel>

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">

        <StackPanel>
            <TextBlock>Upcomming Games</TextBlock>
            <ListBox ItemsSource="{Binding}" Name="GameList"></ListBox>
        </StackPanel>
        <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
            <Button Height="30" Width="100" Margin="10,10,10,10" Click="AddGame_Click">Add New Game</Button>
        </StackPanel>
    </StackPanel>
</StackPanel>

And my code simply set the DataContext of the window to a ObservableCollection

with the need to use TWO collections I created a wrapper class like this

    public class AppModel
{


    public ObservableCollection<Game> gameCollection { get; set; }
    public ObservableCollection<Player> playerCollection { get; set; }

}

And my CS is now setting the DataContext to an object of AppModel

    GameDBEntities _entity = new GameDBEntities();
    AppModel _model;
    public MainWindow()
    {
          InitializeComponent();

          DataContext = model;
    }


    AppModel model
    {
        get
        {
            if (_model == null)
            {
                _model = new AppModel();
            }
            if (_model.gameCollection == null)
            {
                _model.gameCollection = new ObservableCollection<Game>(_entity.Games);
            }
            if (_model.playerCollection == null)
            {
                _model.playerCollection = new ObservableCollection<Player>(_entity.Players);
            }
            return _model;
        }
        set { }

    }

In my Xaml, how can I set the datacontext of the existing listBox to be bound to the Collection Of Games in The AppModel?
Once I get that working I will work on the second listbox on my own.
Thanks!

  • 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-25T22:15:50+00:00Added an answer on May 25, 2026 at 10:15 pm

    You need to add a Path to the Binding. The DatacContext will be the model, the path should point to either collection:

    <ListBox ItemsSource="{Binding gameCollection}" ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why do I need two of them? When I have to use one or
I have one form which need to submit data into two different tables in
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I have downloaded the silver light from this http://www.microsoft.com/silverlight// I need to use this
I have some ASP.NET Master Pages located in one assembly. I need to use
While working in WPF i have the need for a Dynamic Grid. By this
I have two tables (Master, Responses) I need use the Master_Id field from the
I have a need to use extensionless URLs. I do not have access to
I sometimes need to use Visual Studio when I have limited screen real estate
I have a Set that I need to use the findAll closure upon. The

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.