: 그런 식으로, 메인 창에서 수행되는 윈도우 동작은 또한 다른 창을 모두 수행됩니다 약간 예제 (모범 사례) 코드으로 진행합니다.
이 조쉬 스미스이 App.xaml.cs를이 같아야하는 방법을 보여줍니다 것입니다.
namespace MyApplication
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
static App()
{
// Ensure the current culture passed into bindings is the OS culture.
// By default, WPF uses en-US as the culture, regardless of the system settings.
//
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var window = new MainWindow();
// To ensure all the other Views of a type Window get closed properly.
ShutdownMode = ShutdownMode.OnMainWindowClose;
// Create the ViewModel which the main window binds.
var viewModel = new MainWindowViewModel();
// When the ViewModel asks to be closed,
// close the window.
EventHandler handler = null;
handler = delegate
{
viewModel.RequestClose -= handler;
window.Close();
};
viewModel.RequestClose += handler;
// Allow all controls in the window to bind to the ViewModel by
// setting the DataContext, which propagates down the element tree.
window.DataContext = viewModel;
window.Show();
}
}
}
다시 하루의 끝에서, 당신이 당신의 MVVM 응용 프로그램을 레이아웃 할 것입니다 방법에 달려 있습니다.
? @HBB –
@ ZoyaSheikh : 정말로 중요하지는 않지만,'App' 클래스의'Application.OnStartup'에서 할 것입니다. (도랑'StartupUri'는 수동으로 창을 창조하고, 그것을 할당한다) –