새 창을 어떻게 열어야합니까? 나는 현재 다음과 같은 일을하고있다.ViewModel에서 새 창 열기
EventArgs입니다 :
public class GenericViewRequestedEventArgs : EventArgs
{
public GenericViewModel ViewModel { get; private set; }
public GenericViewRequestedEventArgs(GenericViewModel viewModel)
{
ViewModel = viewModel;
}
}
뷰 모델 :
public class MainWindowViewModel : ViewModelBase
{
private RelayCommand _viewSpecificCommand;
public ICommand ViewSpecificCommand
{
get
{
if (_viewSpecificCommand == null)
_viewSpecificCommand = new RelayCommand(x => viewSpecific());
return _viewSpecificCommand;
}
}
public EventHandler<GenericViewRequestedEventArgs> GenericViewRequested;
private void RaiseGenericViewRequested(GenericViewModel viewModel)
{
var handler = GenericViewRequested;
if (handler != null)
handler(this, new GenericViewRequestedEventArgs(viewModel));
}
private void viewSpecific()
{
RaiseGenericViewRequested(_specificViewModel);
}
}
보기 :
public partial class MainWindow : Window
{
private void OnGenericViewRequested(object sender, GenericViewRequestedEventArgs e)
{
GenericWindow window = new GenericWindow(e.ViewModel);
window.ShowDialog();
}
}
이 수행 작업,하지만 코드의 많은 것 같아 난 뒤에 코드와 끝까지 내 관점에서 어떤 방식 으로든.
- viewmodel에 명령을 보내는 것의 논리는 무엇입니까?
- 선택적으로 조건부를 선택적으로 사용하고 (그렇다면 Enabled로 바인드하지 않는 이유) 속성으로 추가 뷰 모델 노출을 피할 수 있습니까?
- XAML에 간단한 이벤트 처리기를 연결해야합니까 (예 :
Click="btnViewSpecific_Click"
)?
대화 상자를 열려면 다음과 같이하십시오. http://stackoverflow.com/questions/3801681/good-or-bad-practice-for-dialogs-in-wpf-with-mvvm – blindmeis