小编CEv*_*per的帖子

AppBar 中按钮的绑定命令不起作用

为什么下面例子中的Command不执行?

我有一个带有 AppBar 和 Button 的命名页面:

   <Page
    x:Class="App13.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" 
    x:Name="myPage"
    >
    <Page.BottomAppBar>
        <AppBar>
           <Button Content="OK" Command="{Binding OkCommand, ElementName=myPage}" />
        </AppBar>
    </Page.BottomAppBar>
</Page>
Run Code Online (Sandbox Code Playgroud)

命令“OkCommand”在代码隐藏中定义如下(使用 MVVM 轻型框架):

public RelayCommand OkCommand
{
    get
    {
        return m_OkCommand
            ?? (m_OkCommand = new RelayCommand(
                                  async () =>
                                  {
                                      await new MessageDialog("OkCommand").ShowAsync();
                                  }));
    }
}
Run Code Online (Sandbox Code Playgroud)

输出窗口中没有绑定错误或任何其他提示,让我知道为什么这不起作用。(另外:如果按钮放在 AppBar 之外,一切正常)

有谁知道这里有什么问题?

c# binding winrt-xaml

5
推荐指数
1
解决办法
3829
查看次数

标签 统计

binding ×1

c# ×1

winrt-xaml ×1