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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:02:11+00:00 2026-06-06T18:02:11+00:00

I have two User Controls already created now I want to use one as

  • 0

I have two User Controls already created now I want to use one as Master User Control and another as Details User control as follows:

1 Parent Control
  1.1 - User Control 1 as Master Control
  1.2 - User Control 2 as Details Control

The Master Control has the List box where I select the name of the Item and the Details Control Displays the all the available Items in stock.
I have Added ItemId in the Parent Control and bound it to the Master Control and Details Control (both controls have ItemId as DP).
When I select the Item from Master the details Grid is not refreshing.

How can I make sure that when I select the Item from Master User Control; the Detail User Control should show me the details?

The Parent Control

 <Grid>
        <StackPanel Orientation="Horizontal"
                    Width="650"
                    HorizontalAlignment="Left"
                    Margin="10,10,0,0">
             <UC:ItemDetailUC ItemId="{Binding ElementName=MainWindowName,Path=ItemId,Mode=TwoWay}" />
             <UC:StockItemDetailsUC ItemId="{Binding ElementName=MainWindowName,Path=ItemId,Mode=TwoWay}"/>
        </StackPanel>
    </Grid>

.

public partial class MainWindow : Window, INotifyPropertyChanged
        {

       private int _ItemId;
            public int ItemId
            {
                get
                {
                    return _ItemId;
                }
                set
                {
                    if (_ItemId == value)
                        return;
                    _ItemId = value;
                    OnPropertyChanged("ItemId");
                }
            }

            public MainWindow()
            {
                InitializeComponent();            
                this.DataContext = this;
            }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;

        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    }

1.1 – User Control 1 as Master Control – ItemDetailUC.XAML

    <UserControl x:Class="LearnWPF.ItemDetailUC"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             Name="ItemDetailUCName"
             d:DesignHeight="100" d:DesignWidth="350">
    <Grid Background="Aqua">
        <StackPanel Orientation="Vertical" Margin="10,10,0,0" >
            <Label Content="Master Control:" Width="350" HorizontalContentAlignment="Center"/>
            <StackPanel Orientation="Horizontal" Width="200" HorizontalAlignment="Left" Margin="10,10,0,0">
                <Label Content="Item :" Width="80"/>
                <ComboBox Name="ItemListComboBox" Width="100"
                          DisplayMemberPath="ItemName"
                          SelectedValuePath="ItemId"
                          SelectedValue="{Binding ElementName=ItemDetailUCName, Path=ItemId}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Margin="10,10,0,0">
                <Label Content="Available Qty :" Width="80"/>
                <TextBox Width="100" Text="{Binding ElementName=ItemListComboBox, Path=SelectedItem.AvailableQty}" />
                 <Label Content="MaxQty :" Width="60"/>
                <TextBox Width="80" Text="{Binding ElementName=ItemListComboBox, Path=SelectedItem.MaxQty}" />
           </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

.

    public static readonly DependencyProperty ItemIdProperty = DependencyProperty.Register("ItemId", typeof(int), typeof(ItemDetailUC));
 public int ItemId
    {
        get
        {
            return (int)GetValue(ItemIdProperty);
        }
        set
        {
            SetValue(ItemIdProperty, value);
        }
    }


       public ItemDetailUC()
    {
        InitializeComponent();
        ItemListComboBox.ItemsSource = Data.GetItemList();
        this.DataContext = this;
    }

1.2 – User Control 2 as Details Control

<UserControl x:Class="LearnWPF.StockItemDetailsUC"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="200" d:DesignWidth="300">
    <Grid>

        <StackPanel Orientation="Vertical" Background="Aquamarine">
             <Label Content="Details Control:" Width="300" HorizontalContentAlignment="Center"/>

        <DataGrid Name="StockItemDetailsDataGrid" Background="Aquamarine"
                  AutoGenerateColumns="False">

             <DataGrid.Columns>
                <DataGridTextColumn Header="Location Name"  Binding="{Binding LocationName}"/>
                <DataGridTextColumn Header="RowNo" Binding="{Binding RowNo}" />
                 <DataGridTextColumn Header="ColumnNo" Binding="{Binding ColumnNo}" />
                 <DataGridTextColumn Header="Qty" Binding="{Binding Qty}" />               
            </DataGrid.Columns>


        </DataGrid>
</StackPanel>
    </Grid>
</UserControl>

.

        public static readonly DependencyProperty ItemIdProperty = DependencyProperty.Register("ItemId", typeof(int), typeof(StockItemDetailsUC));

        public int ItemId
        {
            get
            {
                return (int)GetValue(ItemIdProperty);
            }
            set
            {
                SetValue(ItemIdProperty, value);
            }
        }


        public StockItemDetailsUC()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(StockItemDetailsUC_Loaded);

        }

        void StockItemDetailsUC_Loaded(object sender, RoutedEventArgs e)
        {
            if (ItemId != 0)
            {
                StockItemDetailsDataGrid.ItemsSource = Data.GetItemLocaitonDetails(ItemId);
            }
            this.DataContext = this; 
        }
.

       public class ItemDetailsVO: INotifyPropertyChanged
    {
        private int _ItemId;
        public int ItemId
        {
            get
            {
                return _ItemId;
            }
            set
            {
                if (_ItemId == value)
                    return;
                _ItemId = value;
                OnPropertyChanged("ItemId");
            }
        }

        private String _ItemName;
         private int _AvailableQty;
         private int _MaxQty;
    }





   public class StockItemDetails : INotifyPropertyChanged
    {
        private int _ItemId;
        public int ItemId
        {
            get
            {
                return _ItemId;
            }
            set
            {
                if (_ItemId == value)
                    return;
                _ItemId = value;
                OnPropertyChanged("ItemId");
            }
        }

        private String _LocationName;
        private int _Qty;
        private int _RowNo;
        private int _ColumnNo;
        /..... all properties are implemented
    }
  • 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-06T18:02:13+00:00Added an answer on June 6, 2026 at 6:02 pm

    Don’t use just the ItemID as a dependency property but the item itself. The following scenario should fulfill your requirements:

    Assume that CItem is the type of one record in your master/detail view. In the View that hosts your master and detail controls, use a view model that exposes a List<CItem> or if you dynamically want to add/remove items an ObservableCollection<CItem> which you set as the binding target for the ItemsSource of your master list. In addition, create a dependency property “SelectedObject” of type CItem in the view model. In the master list for SelectedItem create a two way binding to that “SelectedObject” property. In the details view just also bind to properties of “SelectedObject” like

    <TextBox Text="{Binding SelectedObject.MyProperty, Mode=TwoWay}" />
    

    Now when the user in the master view selects a different record the SelectedObject property gets updated and due to that all detail bindings on that also will get an update.

    Edit:
    So if you need additional logic, think about using a callback funktion when the value of the dependency property ItemID changes. Use the PropertyMetadata with the PropertyChangedCallback constructor when registering the dependency property. The callback function is called each time when the value of the dependency property changes. In this callback function you can trigger the additional logic you mentioned for loading/preparing the item for the details view.

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

Sidebar

Related Questions

I have two user controls, in one of them I have a textbox, i
I have a user control in a master page with two drop down lists.
I have a user control in my wp7 application which contains two text boxes
I have two models User and Admin(with RailsAdmin) that use Devise. I sign in
I have a user control that has a grid (the one you get automatically
Maybe someone can help me out. I have created a simple web user control,
I have a WinForms control on which I want to display two things: An
I have two user controls A and B, where B depends on the existence
I'm having an issue where I have made a user control with two content
I have two user controls that need to add a class atribute to 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.