我的Xamarin.Forms应用程序中的Entry对象有问题。
当我在Android设备上使用该应用时,没有问题。我可以在其中输入文本,然后在0
事件中使用此文本。但是在UWP App上,我的var materialized = query.ToList();
return (materialized.Count != 0)
? (IActionResult)new ObjectResult(materialized)
: (IActionResult)NotFound();
对象上有一个空引用。在这里你可以找到我的代码和重复:
ButtonPressed
这是我的xaml观点:
Entry
我有点迷失,为什么我的条目在我的UWP应用程序中不起作用?
答案 0 :(得分:1)
最后我知道问题出在哪里! 始终隐藏在中。
请参阅SearchVideo
方法签名:
void SearchVideo(object sender);
现在是Pressed
事件签名:
void Pressed(object sender, EventArgs e);
你现在可能也看到了,对吗?问题在于,方法的签名与事件预期的不同。出于某种原因,这会抛弃XAML解析器并打破x:Name
绑定,但仍然可以编译!
因此,要解决此问题,您需要的唯一更改是添加EventArgs
参数:
private void SearchVideo(object sender, EventArgs e)
{
var ResultPage = new PageFeedYouTube(Vid.Text);
Navigation.PushAsync(ResultPage);
}
我仍在微笑着这个臭虫是多么鬼鬼祟祟。哦,开发人员每天都在学习新东西。
答案 1 :(得分:0)
为您的按钮x:Name
添加<Button Text="Recherche" x:Name="RechercheBtn" />
。
现在,在您的代码中,向该按钮添加一个命令,如下所示:
public Search ()
{
InitizializeComponent();
Vid.Text= "lol";
RechercheBtn.Command = new Command(() => SearchVideo(Vid.Text));
}
然后,修改您的SearchVideo
功能:
void SearchVideo(string vidText)
{
Application.Current.MainPage = new PageFeedYouTube(vidText);
}