【发布时间】:2013-10-10 08:29:46
【问题描述】:
创建了一个新的 WPF 4.5 MVVM 轻量级应用程序后,我想更改启动 URI,以便在应用程序启动之前进行一些检查。我对 App.xaml 进行了以下更改:
<Application x:Class="MvvmLight1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MvvmLight1.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="MainWindow.xaml"
mc:Ignorable="d">
收件人:
<Application x:Class="MvvmLight1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MvvmLight1.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
并在App.xaml.cs 中添加了OnStartup 方法:
public partial class App : Application
{
static App()
{
DispatcherHelper.Initialize();
}
protected override void OnStartup(StartupEventArgs e)
{
//base.OnStartup(e);
MainWindow win = new MainWindow();
win.Show();
}
}
这样做似乎改变了窗口运行的上下文。我确实尝试将数据上下文设置为 MainViewModel,但这似乎没有帮助。
【问题讨论】:
-
您对
Application的定义做了哪些更改?我看不出有什么区别……你还有StartupUri="MainWindow.xaml"。你在哪里设置DataContext?我也没有看到。 -
很好看,虽然这完全是因为我的格式不好!
-
就 DataContext 而言,更改它没有任何区别,这就是我没有包含它的原因。
-
把它从什么改成什么?请向我们展示,以便我们了解您的问题的背景。
标签: c# .net wpf mvvm mvvm-light