C#新类文件可以';I don’我现在没法工作。

C#新类文件可以';I don’我现在没法工作。,c#,xaml,C#,Xaml,我正在为我的程序创建一个新的类文件,所以我将一些代码移到了这个新的类文件中 namespace App1 { class BL_PageContent { public static string VarOutput { get; set; } async public void btnCourse1_Click(object sender, RoutedEventArgs e) { string[] na

我正在为我的程序创建一个新的类文件,所以我将一些代码移到了这个新的类文件中

namespace App1
{
    class BL_PageContent
    {
        public static string VarOutput { get; set; }

        async public void btnCourse1_Click(object sender, RoutedEventArgs e)
        {
            string[] names = new string[3] { "COP3488C,", "UWP1,", "This course is mobile app development." };
            await WorkerAsync(names);
        }


        async private void btnCourse2_Click(object sender, RoutedEventArgs e)
        {
            string[] names = new string[3] { "DOP3488B,", "UWC1,", "This course is Cloud Computing." };
            await WorkerAsync(names);
        }

        async private void btnCourse3_Click(object sender, RoutedEventArgs e)
        {

            string[] names = new string[3] { "BOP3589,", "UWP2,", "This course Computer Programming Java 1." };
            await WorkerAsync(names);

        }

        private async Task WorkerAsync(string[] names)
        {
            string VarOutput = "";

            for (int i = 0; i < names.Length; i++)
            {
                VarOutput = VarOutput + names[i] + "  ";
            }


        }
    }
}
}

这是我用于显示的xaml。这就是出现错误的原因我知道这一定是链接到这个文件的原因是什么?严重性代码说明项目文件行抑制状态错误CS1061“MainPage”不包含“btnCourse1\u Click”的定义,并且找不到接受“MainPage”类型的第一个参数的扩展方法“btnCourse1\u Click”(是否缺少using指令或程序集引用?)

页面
x:Class=“App1.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local=“使用:App1”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable=“d”>

你不能那样做。请参阅XAML中的代码:

Page
x:Class="App1.MainPage"
XAML包含有关在何处查找视图的代码的信息。如上所述,它是
App1.MainPage
。因此,XAML将在
MainPage
中查找这些:

<Button x:Name="btnCourse1" Content="Course 1" HorizontalAlignment="Left" Margin="41,337,0,0" VerticalAlignment="Top" Click="btnCourse1_Click"/>

<Button x:Name="btnCourse2" Content="Course 2" HorizontalAlignment="Left" Margin="41,374,0,0" VerticalAlignment="Top" Click="btnCourse2_Click"/>

// ... so on

// ... 等等
因为你移动了它,它就不在了。所以它在抱怨。你没有理由这么做。如果这是一种试图重构或移动代码以实现可重用性的尝试,那么这不是一种方法


如果要重用代码,请创建可重用类,然后将其传递给viewmodel。将视图绑定到viewmodel。

这是我们被告知要为作业做的,不确定为什么我们可能会更多地构建该类,但不确定。所以我必须在主页上设置btnCourse1\u Click()?
Page
x:Class="App1.MainPage"
<Button x:Name="btnCourse1" Content="Course 1" HorizontalAlignment="Left" Margin="41,337,0,0" VerticalAlignment="Top" Click="btnCourse1_Click"/>

<Button x:Name="btnCourse2" Content="Course 2" HorizontalAlignment="Left" Margin="41,374,0,0" VerticalAlignment="Top" Click="btnCourse2_Click"/>

// ... so on