글쎄 주로 응용 프로그램이 어떻게 보이는지 (즉, 동시에 열리는 창의 수, 모달 창이 아닌지 등)에 따라 다릅니다.
일반적인 권장 사항은 이 아닙니다. "pure"MVVM을 시도해보십시오. 나는 종종 "Zero code-behind가 있어야한다"는 식으로 읽는다.
현재 프로젝트를 모델 어셈블리/프로젝트 ViewModel 어셈블리/프로젝트와 어셈블리/프로젝트보기로 분리하고 있습니다. 이 경우 을 다른 "Core"어셈블리로 이동해야합니까?
뷰와 뷰 모델을 서로 다른 어셈블리로 분리하면 viewModel에서 뷰와 관련된 내용을 참조하지 않도록 할 수 있습니다. 이처럼 강한 이별로 당신은 잘 될 것입니다.
두 개의 다른 어셈블리를 사용하여 ViewModel과 모델을 분리하는 것도 좋은 생각 일 수 있지만 모델이 어떻게 생겼는지에 달려 있습니다. 필자는 개인적으로 3 계층 아키텍처를 선호하므로 일반적으로 내 모델은 WCF 클라이언트 프록시이며 실제로 자체 어셈블리에 저장됩니다.
"코어"어셈블리는 항상 좋은 생각이지만 (IMHO) 응용 프로그램의 모든 레이어에서 사용할 수있는 기본 유틸리티 메서드를 노출하는 것입니다 (기본 확장 메서드 .... 등). .
조회수 (표시 방법 ... 등)에 대해 지금 은 간단한입니다. 개인적으로 필자는 내 Views의 코드 숨김에서 내 ViewModels을 인스턴스화하는 것을 좋아합니다. 또한 내 ViewModels에 이벤트을 자주 사용하므로 연관된보기가 통보되어 다른보기를 열어야한다고 예를 들어 알립니다.
예를 들어, 시나리오 당신은해야 아이 창을 표시하는 MainWindow를이 때 사용자가 버튼을 클릭 :
// Main viewModel
public MainViewModel : ViewModelBase
{
...
// EventArgs<T> inherits from EventArgs and contains a EventArgsData property containing the T instance
public event EventHandler<EventArgs<MyPopupViewModel>> ConfirmationRequested;
...
// Called when ICommand is executed thanks to RelayCommands
public void DoSomething()
{
if (this.ConfirmationRequested != null)
{
var vm = new MyPopupViewModel
{
// Initializes property of "child" viewmodel depending
// on the current viewModel state
};
this.ConfirmationRequested(this, new EventArgs<MyPopupViewModel>(vm));
}
}
}
...
// Main View
public partial class MainWindow : Window
{
public public MainWindow()
{
this.InitializeComponent();
// Instantiates the viewModel here
this.ViewModel = new MainViewModel();
// Attaches event handlers
this.ViewModel.ConfirmationRequested += (sender, e) =>
{
// Shows the child Window here
// Pass the viewModel in the constructor of the Window
var myPopup = new PopupWindow(e.EventArgsData);
myPopup.Show();
};
}
public MainViewModel ViewModel { get; private set; }
}
// App.xaml, starts MainWindow by setting the StartupUri
<Application x:Class="XXX.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...
StartupUri="Views/MainWindow.xaml">
좋은 질문. 시작을 위해, 나는 보통 app.xaml.cs 코드를 통해 모든 것을 부트 스트랩하지만, 항상 나를 더러운 느낌으로 만듭니다. – hschne
MVVM 스타일의 여러 창을 사용하여이 항목에 대한 최근 [답변] (http://stackoverflow.com/questions/20242817/resolving-wpf-windows-in-structure-map/21763694#21763694)을 볼 수 있습니다. . –