我的xaml.cs页面未在Mainpage.xaml类中获得按钮的“ x:name”,有人知道为什么我会收到此错误吗?我是Xamarin的新手,我真的不知道自己在做什么,我将在下面发布代码。 谢谢你一百万!!!!
MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:VideoPlayer"
xmlns:forms="clr-
namespace:Plugin.MediaManager.
Forms;assembly=Plugin.MediaManager.Forms"
x:Class="VideoPlayer.MainPage">
<StackLayout>
<forms:VideoView WidthRequest="360"
HeightRequest="202"
/>
<Button x:Name ="PlayStop"
Text="Play"
Clicked= "Button_Clicked">
</Button>
</StackLayout>
</ContentPage>
xaml.cs:
using Plugin.MediaManager;
using Plugin.MediaManager.Abstractions.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace VideoPlayer
{
public partial class MainPage : ContentPage
{
String videoUrl = "https://www.youtube.com/watch?v=kZ-eFt5kSSQ";
public MainPage()
{
InitializeComponent();
}
private void PlayStop_Clicked(object sender, EventArgs e)
{
if (PlayStop.Text == "Play")
{
CrossMediaManager.Current.Play(videoUrl,MediaFileType.Video);
};
}
}
}