Hi Guysm
i have 2 different viewModels and i want to display them in a single WPF windows any ideas if that is posible as all my code for one Viewmodel is displayed Xaml and this line of code behind for main window
public partial class MainWindow : Window
{
public EscortViewModel eViewModel { private set; get; }
public MainWindow()
{
InitializeComponent();
eViewModel = new EscortViewModel();
eViewModel.LoadCustomer();
DataContext = eViewModel;
}
}
the other issue i have I'm using EditCommand class which implement ICommand.
is it possible to use the same class for both view Model even if i decided to use seprate wpf window for each model
here is my MainWindow XAML
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:WpfGlobalReach.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:EscortViewModel}"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="687.552">
ItemsSource="{Binding Escorts}"
DisplayMemberPath="FirstName"
SelectedItem="{Binding CurrentEscort, Mode=TwoWay}"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" >
ItemsSource="{Binding Escorts}"
DisplayMemberPath="FirstName"
SelectedItem="{Binding CurrentEscort, Mode=TwoWay}"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" Height="58">
Text="{Binding CurrentEscort.FirstName, UpdateSourceTrigger=PropertyChanged}">
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Princy GuptaPosted Apr 6, 2014, 11:50 PM
http://social.msdn.microsoft.com/Forums/vstudio/en-US/9386e7aa-336a-4d9e-8fac-e5a70cd023d5/is-two-view-models-and-one-view-good-idea-in-mvvm-pattern-?forum=wpf
http://billwagner.azurewebsites.net/blog/multiple-view-models-implies-multiple-datacontexts
Abbas HamzaPosted Apr 7, 2014, 2:44 AM
that is all well and good from what I understood it does swith between 2 view model (correct me if I am wrong)..
in my case I had a list view wuth 3 item to be displayed 2 item bind to one viewModel and the third item is linked to a second viewModel I.e. firstName and escortId from viewModel 1 and addressId from model from viewModel 2.
hope that explain what I wanted to achieve