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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:36:21+00:00 2026-05-12T10:36:21+00:00

I have a class like this: public class Contest { List<ContestTeam> Teams { get;

  • 0

I have a class like this:

public class Contest {
    List<ContestTeam> Teams { get; set; }
}

public class ContestTeam {
    int TeamId { get; set; }
    int FinalScore { get; set; }
}

And my view model looks like this:

public class ScheduleViewModel {
    int CurrentTeamId { get; }
    List<Contest> Schedule { get; }
}

My XAML looks something like this:

<ListBox ItemsSource="{Binding Path=Schedule}">
    <ListBox.ItemTemplate>
        <DataTemplate>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition  />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" Orientation="Horizontal">
                    <!-- TODO: DataContext is currently hard coded to 425 - this needs to be fixed -->
                    <StackPanel Orientation="Horizontal" 
                            DataContext="{Binding Path=Teams, Converter={StaticResource CurrentTeam}, ConverterParameter=425}">

                        <TextBlock Text="{Binding SomeProperty}" />
                    </StackPanel>

                    <Button Content="Delete" />
                </StackPanel>

                <ListBox Grid.Row="1" ItemsSource="{Binding Teams}">
                    <!-- a list of all the teams -->
                </ListBox>
            </Grid>

        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Essentially, so I can continue developing I created a value converter (CurrentTeam) and hard-coded the TeamId as the ConverterParameter so I can continue developing the view. But I’m at a bit of an impasse. Is there a way (using XAML) to bind the DataContext of the StackPanel to the ContestTeam in the Teams collection that matches the value of ScheduleViewModel.TeamId?

My last recourse will be to just use the Loaded event of the StackPanel to set it’s DataContext in the code-behind, but I’d like to avoid that. Are there any XAML Ninjas out there who can help me figure this out?

  • 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-12T10:36:21+00:00Added an answer on May 12, 2026 at 10:36 am

    There’s no way to make queries in XAML bindings. In this case, since you really have two input values (Teams and CurrentTeamId), just use a MultiBinding and a IMultiValueConverter:

    public class FindContestByIdConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType,
                              object parameter, CultureInfo culture)
        {
            var teams = (IEnumerable<ContestTeam>)values[0];
            var teamId = (int)values[1];
            return teams.Single(t => t.TeamId == teamId);
        }
    
        // ConvertBack that throws NotSupportedException
        ...
    }
    

    and then XAML:

    <StackPanel>
      <StackPanel.DataContext>
        <MultiBinding Converter="{StaticResource FindContestByIdConverter}">
          <Binding Path="Teams"/>
          <Binding Path="CurrentTeamId" />
        </MultiBinding>
      </StackPanel.DataContext>
      ...
    </StackPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 339k
  • Answers 339k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're trying to measure code running time, the stopwatch… May 14, 2026 at 4:33 am
  • Editorial Team
    Editorial Team added an answer The correct way to do this is: typedef void (*callback_function)(void);… May 14, 2026 at 4:33 am
  • Editorial Team
    Editorial Team added an answer You can use the built-in enumerate to get both index… May 14, 2026 at 4:33 am

Related Questions

I have a list of cities and a list of countries and both of
The story: I had class User and class Organization: User. I did not use
I'm trying to figure out the best way to handle loading objects with different
I'm writing a microformats parser in C# and am looking for some refactoring advice.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.