UWP 中整数 CommandParameter 的内联语法 XAML

Inline syntax for integer CommandParameter in UWP XAML

我想在 XAML 和

中使用整数 CommandParameter
 <MenuFlyoutItem Text="Save" Command="{Binding}" CommandParameter="1"/>

但是,这将以 string“1”作为参数启动我的 ICommand。我知道我可以添加

<x:Int32 x:Key="SaveCommandCode">1</x:Int32>

作为资源,然后使用 "{StaticResource SaveCommandCode}"。是否有更短的内联语法?我已经尝试 "{x:Int32 1}" 但它不起作用。

只需使用 int.TryParse() 或 int.Parse() 转换命令中的字符串 - 文字将始终被视为字符串。

我认为不使用资源的最短解决方案是:

<MenuFlyoutItem Text="Save" Command="{Binding}">
    <MenuFlyoutItem.CommandParameter>
        <x:Int32>1</x:Int32>
    </MenuFlyoutItem.CommandParameter>
</MenuFlyoutItem>