ChildWindow From ViewModel

Sep 9, 2011 at 2:10 PM

I hae created a child window xaml sepeare file something like

Example:

<controls:ChildWindow x:Class="Client.Views.TestChild"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
                      Width="300"
                      Height="300">
</controls:ChildWindow>

TestChild.xaml.cs
public
TestChild(List<ExecEnqRowConverter> selectedExecsOfExecEnq)
This will call from another class view Model when user selected and click on Button....

MainGridViewModel.cs
var testChild = new TestChild(selectedExecsOfExecEnqList);

So how can I add my TestChild to Visual Tree

view: MainGrid.Children.Add(testChild );

As in MVVM I dont have MainGrid object in MainGridViewModel.cs
Sep 9, 2011 at 2:13 PM

You wouldn't create it in your ViewModel.  You would define it in your XAML.  You will need to add a DependencyProperty to your control called ItemsSource and use databinding instead of passing the collection to a constructor.

Sep 9, 2011 at 2:30 PM

Ok Thnk you very much