我有一个WPF应用程序,当我尝试向App类添加任何事件处理程序时,它无法编译。
以下是所有代码和我得到的异常。该应用程序使用MVVM工具包 - 所以这可能是一个因素。
如果有人能告诉我可能缺少或执行不正确的内容,那将不胜感激。
App.xaml代码:
<Application x:Class="MyClient.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Sample.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Startup="Application_Startup">
<Application.Resources>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<!-- Resources scoped at the Application level should be defined here. -->
<Style x:Key="TextBlockStyleFooter" TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Margin" Value="1"/>
</Style>
<Style x:Key="TextBlockStyleClock" TargetType="TextBlock">
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="White"/>
<!--<Setter Property="Margin" Value="0, -1,"/>-->
<Setter Property="TextAlignment" Value="Center"/>
</Style>
<Style x:Key="BorderStyle1" TargetType="Border">
</Style>
</Application.Resources>
App.xaml.cs 代码:
using System;
using System.Windows;
using System.Windows.Threading;
using GalaSoft.MvvmLight.Threading;
namespace Sample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
static App()
{
DispatcherHelper.Initialize();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
}
}
}
当我尝试编译这个时,我会收到以下异常:
Error 1 'MyClient.App' does not contain a definition for 'Application_Startup' and no extension method 'Application_Startup' accepting a first argument of type 'EdgePokerClient.App' could be found (are you missing a using directive or an assembly reference?) C:\projects.git\MyClient\src\MyClient\App.xaml 7 73 MyClient
<Application x:Class="MyClient.App"
- Josh