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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:14:50+00:00 2026-06-12T22:14:50+00:00

I have a window with a number of controls, that necessarily reference each others

  • 0

I have a window with a number of controls, that necessarily reference each others viewModels. I want to move a group of related controls into a custom UserControl, and when I do I have problems with binding to the now-embedded controls from other controls in the window.

E.g. In my window I have a Grid. In one cell of the Grid I have StackPanel containing two custom UserControls:

<StackPanel>
    <KtWpf:TicketGridControl x:Name="ticketGrid" />
    <KtWpf:TicketViewControl x:Name="ticketView" />
</StackPanel>

In another cell of the Grid, I have another custom UserControl that binds to the current item in the grid:

<local:AddressView x:Name="addressView"
    currentItem="{Binding ElementName=ticketGrid,Path=viewModel.tickets.CurrentItem}" />

And that binding works fine.

But what I want is to move the ticketGrid and the ticketView into a new custom UserControl. This is easily done:

<UserControl
        x:Class="KorEnterprise.EnterpriseMobile.MyTickets"
        ...
        >
    <StackPanel>
        <KtWpf:TicketGridControl x:Name="ticketGrid" />
        <KtWpf:TicketViewControl x:Name="ticketViewControl" />
    </StackPanel>
</UserControl>

And then in the Grid, I replace the StackPanel with:

<local:MyTickets x:Name="myTickets" />

And then I’d expect the binding for addressView to change to:

<local:AddressView x:Name="addressView"
    currentItem="{Binding ElementName=myTickets,Path=ticketGrid.viewModel.tickets.CurrentItem}" />

But this doesn’t work. I get a BindingExpression error at runtime:

System.Windows.Data Error: 40 : 
BindingExpression path error: 'ticketGrid' property not found on 'object' ''MyTickets' (Name='myTickets')'. 
BindingExpression:Path=ticketGrid.viewModel.tickets.CurrentItem; 
DataItem='MyTickets' (Name='myTickets'); 
target element is 'AddressView' (Name='addressView'); 
target property is 'currentItem' (type 'TicketVM')

And I don’t understand why. I get no errors at compile time – and I get no errors in the code.

This, for example, does not throw an exception:

public MainWindow()
{
    ...
    this.applicationExiting += new ApplicationExitingEventHandler(this.myTickets.ticketGrid.applicationExitingEventHandler);
    ...
}

When I walk through in the debugger, this.myTickets exists, and this.myTickets.ticketGrid exists, and the event handler hooks up just fine.

But when the XAML starts doing its silent magic stuff, hooking up the bindings, for some reason this.myTickets.ticketGrid doesn’t exist.

And I’m at a loss to understand why.

  • 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-06-12T22:14:51+00:00Added an answer on June 12, 2026 at 10:14 pm

    I’m not at all sure that this is the best approach, but it does work. It just involves more plumbing than I would have liked.

    • Create a view model class, and set an instance of it to be the DataContext for the control.
    • Create a ticket collection property on the view model
    • Set the view model’s ticket collection to the ticketGrid’s ticket collection, when the user control is constructed
    • Bind the AddressView control’s currentItem property to the view model’s ticket collection
    • And most important – raise PropertyChanged when the view model’s ticket collection is changed.

    This works, but I’d love to find something simpler:

    public partial class MyTickets : KorUserControl
    {
        public MyTickets()
        {
            InitializeComponent();
    
            this.DataContext = new MyTicketsVM();
            this.viewModel.tickets = this.ticketGrid.viewModel.tickets;
        }
    
        public MyTicketsVM viewModel
        {
            get { return this.DataContext as MyTicketsVM; }
        }
    }
    
    public class MyTicketsVM : MyViewModelBase
    {
        private QueryableCollectionView _tickets;
        public QueryableCollectionView tickets
        {
            get { return this._tickets; }
            internal set
            {
                this._tickets = value;
                notifyPropertyChanged("tickets");
            }
        }
    }
    
    <local:AddressView
        x:Name="addressView"
        currentItem="{Binding ElementName=myTickets,Path=viewModel.tickets.CurrentItem}"
        />
    

    (Note: MyViewModelBase implements INotifyPropertyChanged)

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

Sidebar

Related Questions

I have a ListView in a WPF window containing a number of GridViewColumns. The
Scenario I have a C# windows forms application that has a number of processes.
I have a large number of ViewModel classes. For each of these classes, there
I have a number of utilities that were written in the days of yore
I have a window, in which i have many controls, UserControls or controls derived
I have two related problems that occur in the following situation. I have a
i have a user control that i want to build on. right now it
I have in my model an object, that when modified requires a large number
I have a simple WrapPanel which contains a number of wide controls. When I
I have a grid that I dynamically need to resize in the number of

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.