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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:13:22+00:00 2026-05-28T06:13:22+00:00

In my MainWindow, I’ve got a ListBox whose ItemsSource is bound to an ObservableCollection

  • 0

In my MainWindow, I’ve got a ListBox whose ItemsSource is bound to an ObservableCollection of Layout POCO objects:

<ListBox x:Name="ListBox" ItemsSource="{Binding Layouts}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel IsItemsHost="True" Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

Also, in the MainWindow, we define the visual representation of a Layout object using a UserControl (LayoutUserControl):

<DataTemplate DataType="{x:Type local:Layout}">
   <local:LayoutUserControl />
</DataTemplate>

When we add objects to the Layouts collection, we see new LayoutUserControls populate the ListBox. This is pretty straight forward.

Now, what I’d like to do, is somehow communicate from the MainWindow to the individual LayoutUserControls. Specifically, from the MainWindow, I want to call a single method on each of the LayoutUserControls… If I attempt to iterate through the ListBox’s Items collection, all I get is a reference to the Layout objects, not the LayoutUserControls. Since the LayoutUserControls are defined in a DataTemplate, I don’t have a named reference to access them…

Is there a WPF construct that supports this type of interaction from parent to child controls? RoutedEvents were my first thought, but they only support child to parent (bubble) communication. Perhaps commands are the way to go?

Any help would be appreciated.

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-28T06:13:23+00:00Added an answer on May 28, 2026 at 6:13 am

    Yes, there is a method which you should never use, it’s the ItemContainerGenerator.

    You should, as you noted yourself, set up the communication differently, commands sound reasonable. Expose a command on the Layout and bind the UserControl to it. Or create an event and make the UserControl subscribe to it, then you can raise that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my MainWindow I have an ObservableCollection which is shown in a Listbox per
In MainWindow.xaml I have ... <TextBlock x:Name=tbCpu Text={Binding Path=activeTower.cpuTotal} /> ... and in MainWindow.xaml.cs
I have the following keybindings in my MainWindow: <KeyBinding Command={Binding OpenCommand} Gesture=Ctrl+O/> <KeyBinding Command={Binding
In a simple WPF, I have renamed MainWindow class to MyClass and I got
void MainWindow::addRadioToUI() { int button_cunter=4; while(!database.isEmpty()) { button_cunter++; QPushButton *one = new QPushButton(Play: +name(get_r.getTrackId()));
I have public partial class MainWindow : Window Also I have got some static
What's wrong with public partial class MainWindow : Window { public ObservableCollection<TabViewModel> Tabs {
public MainWindow() { CommandManager.AddExecutedHandler(this, ExecuteHandler); } void ExecuteHandler(object sender, ExecutedRoutedEventArgs e) { } Error
I have a KMainWindow: //file.h class MainWindow: public KMainWindow { public: MainWindow(QWidget *parent =
I am using a QStackedWidget on my mainWindow. The firstPageWidget on stackedWidget contains 3

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.