WPF Application Using MVVM Toolkit Will Not Compile Using StartupEventHandler

I have a WPF application that does not compile when I try to add an event handler to the App class.

Below is all the code and the exception that I get. An application uses the MVVM toolkit - so this can be a factor.

If someone can tell me what I can lose or do wrong, it would be very helpful.


App.xaml Code:

<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 Code:

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)
        {

        }
    }
}

When I try to compile this, I get the following exception:

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
+3
source share
2 answers

, XAML MyClient.App, Sample. . , , (Sample.App), MyClient.App.

, x: Name XAML.

. , , , , .

+3

, , . , x: class . , , Startup = "Application_Startup" XAML, . , .

My Fix -

private void Application_Startup(object sender, StartupEventArgs e){}

Startup="Application_Startup"

xaml. , -.

0

Source: https://habr.com/ru/post/1780574/


All Articles