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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:47:05+00:00 2026-05-15T07:47:05+00:00

I have a datagrid with master detail implementation as follows: <data:DataGrid x:Name=dgData Width=600 ItemsSource={Binding

  • 0

I have a datagrid with master detail implementation as follows:

<data:DataGrid x:Name="dgData"  Width="600" ItemsSource="{Binding Path=ItemCollection}"
                       HorizontalScrollBarVisibility="Hidden" CanUserSortColumns="False" RowDetailsVisibilityChanged="dgData_RowDetailsVisibilityChanged">
                    <data:DataGrid.Columns>
                        <data:DataGridTextColumn Header="Item" Width="*" Binding="{Binding Item,Mode=TwoWay}"/>
                        <data:DataGridTextColumn Header="Company" Width="*" Binding="{Binding Company,Mode=TwoWay}"/>

                    </data:DataGrid.Columns>
                    <data:DataGrid.RowDetailsTemplate>
                        <DataTemplate>
                            <data:DataGrid x:Name="dgrdRowDetail" Width="400" AutoGenerateColumns="False" HorizontalAlignment="Center" 
                                       HorizontalScrollBarVisibility="Hidden" Grid.Row="1">
                                <data:DataGrid.Columns>
                                    <data:DataGridTextColumn Header="Date" Width="*" Binding="{Binding Date,Mode=TwoWay}"/>
                                    <data:DataGridTextColumn Header="Price" Width="*" Binding="{Binding Price, Mode=TwoWay}"/>
                                    <data:DataGridTemplateColumn>
                                        <data:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Content="Show More Details" Click="buttonShowDetail_Click"></Button>
                                            </DataTemplate>
                                        </data:DataGridTemplateColumn.CellTemplate>
                                    </data:DataGridTemplateColumn>
                                </data:DataGrid.Columns>
                            </data:DataGrid>
                        </DataTemplate>
                    </data:DataGrid.RowDetailsTemplate>
                </data:DataGrid>

I want to open a Child window in clicking the button which shows more details about the product.

I’m using MVVM pattern. My Model contains a method which takes the Item name as input and returns the Details data.

My problem is how should I pass the Item to ViewModel which will get the Details data from Model? And where should I open the new Child Window? In View or ViewModel?

  • 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-15T07:47:06+00:00Added an answer on May 15, 2026 at 7:47 am

    Opening the child window from a view model violates the separation between view and view model that the pattern is supposed to be all about. So, you probably don’t have much choice about where you open the child window from – the code behind for the page that the grid is on. (And that violates the pattern as well, but, short of a complicated solution, it’s about all you can do.) I use the MVVM pattern, but I’m not “religious” about it. I will violate some precepts of the pattern when efficiency dictates.

    As far as passing the item to the ViewModel – I suppose you can create a property on the ViewModel that represents an id for the item. I’ve been using child windows as data entry forms for update and add. I tend to create a ViewModel for each one of them. In your case, you would have a ViewModel that represents the details of the item. There would be some sort of ID related to the item and details. That would be a public property on the ViewModel. You could create a constructor for the child window that takes that ID as a parameter. Then, the child window constructor could create the ViewModel and send it the ID.

    Something like this – where DomainEdit is the name of the child window.

        public DomainEdit()
        {
            InitializeComponent();
    
            devm = new DomainEditVM();
            DataContext = devm;
        }
    
        public DomainEdit(Guid domainId) : this()
        {
            devm.DomainId = domainId;
            devm.GetDomain();
            txtTitle.Text = "Edit Domain";
        }
    

    Then, from code behind where the button click for the grid occurs, you create the child window with the new constructor, passing the id that you get from the item binding in the grid row, and an independent view model for the child window takes over.

    At least, that is what has been working for me.

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

Sidebar

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.