问题描述
您好,
我正在使用MVVM模式将ViewPage中AutoSuggestBox的属性绑定到我的ViewModel。当我在Grid或stackPanel中时,这很好。
I am using the MVVM pattern to bind the properties of the AutoSuggestBox in a ViewPage to my ViewModel. This works fine when I am inside a Grid or a stackPanel.
但是一旦我将AutoSuggestBox放在Button的MenuFlyout中。我得到以下错误:
But once I put the AutoSuggestBox inside a MenuFlyout of a Button. I get the following Error:
错误 对象引用未设置为实例一个对象。
Error Object reference not set to an instance of an object.
< Button>
<Button>
< Button.Flyout>
<Button.Flyout>
< MenuFlyoutItem>
&NBSP; &NBSP; < MenuFlyoutItem.Template>
<MenuFlyoutItem >
<MenuFlyoutItem.Template>
&NBSP; < ControlTemplate TargetType =" MenuFlyoutItem">
<ControlTemplate TargetType="MenuFlyoutItem">
< AutoSuggestBox Header ="你叫什么名字?"
TextChanged =" {x:Bind ViewModel.FilterUsuals}"
QuerySubmitted =" {x:Bind ViewModel.ProcessQuery}"
SuggestionChosen =" {x:Bind ViewModel.ProcessChoice}"
ItemsSource =" {Binding Elements}"
Text =" {x:Bind ViewModel.SearchText,Mode = TwoWay}" ;
QueryIcon =" Find" />
<AutoSuggestBox Header="What's your name?" TextChanged="{x:Bind ViewModel.FilterUsuals}" QuerySubmitted="{x:Bind ViewModel.ProcessQuery}" SuggestionChosen="{x:Bind ViewModel.ProcessChoice}" ItemsSource="{Binding Elements}" Text="{x:Bind ViewModel.SearchText, Mode=TwoWay}" QueryIcon="Find" />
< / ControlTemplate>
&NBSP; &NBSP; < /MenuFlyoutItem.Template>
< / MenuFlyoutItem>
</ControlTemplate>
</MenuFlyoutItem.Template>
</MenuFlyoutItem>
关于如何在MenuFlyoutItem中绑定AutoSuggestBox的属性的任何指导??
Any guidance on how to bind the properties of AutoSuggestBox inside the MenuFlyoutItem??
谢谢你们..
推荐答案
据我所知,你无法绑定一个事件到ControlTemplate中的事件处理程序。您可以使用
得到它。
As far as I know, you could not bind an event to event handler in ControlTemplate. You could useEventTrigger to get it.
这是一个类似的线程
"为什么我不能在数据模板中使用{x:绑定{RelativeSource Self}}?"供您参考。
This is a similar thread "Why can't I use {x:Bind {RelativeSource Self}} in a data template?" for your reference.
最好的问候,
Xavier Eoro
Xavier Eoro
这篇关于[UWP]问题:如何绑定到MenuFlyoutItem内的autoSuggestBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!