Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I open a page and assign its datacontext
    primarykey
    data
    text
    <p>my question is relatively easy, I guess. I have a page to display my data. On a click on a button I want to open a new page with the datacontext of an element 2 layers above the datacontext of the current element.</p> <p>Explanation:</p> <p>My ViewModel is a class (ViewModelContainer) that contains more ViewModels. One is a summary of values and one is the detailed view of that.</p> <pre><code>public class SummaryViewModel { public int somevalue; // is a property public ObservableCollection&lt;SummarizedItems&gt; items; // is a property } public class DetailsViewModel { public int someOthervalue; // is a property public int stuffA; // is a property public int stuffB; // is a property } public class ViewModelContainer : ViewModelBase { private SummaryViewModel _sum; public SummaryViewModel sum { } // is a property private DetailsViewModel _det; public DetailsViewModel det { } // is a property } </code></pre> <p>The View where I can press a button is bound to the value of the ObservableCollection of SummaryViewModel. Everything is fine till now. When I press the button, a new page, showing the details should be opened. I use an ICommand to handle the click, and pass it the details view as a CommandParameter.</p> <pre><code>&lt;Button Name="OpenDetailsButton" Command="{Binding Path=ACommand}" CommandParameter="{DynamicResource Details}" </code></pre> <p>I define a page as a resource in the same file, where the datacontext is still ViewModelContainer. </p> <pre><code>&lt;pages:DetailsViewPage DataContext="{Binding Path=det }" x:Key="Details"/&gt; </code></pre> <p>The page opens, but the datacontext is not available. I get the following error:</p> <pre><code> System.Windows.Data Error: 3 : Cannot find element that provides DataContext. </code></pre> <p>Has anyone an idea how I could open the details view and providing the datacontext? I cannot move the DetailsViewModel to another class, because it is only possible to update it there.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload