UWP XAML中整数CommandParameter的内联语法

时间:2019-06-09 20:31:51

标签: uwp uwp-xaml

我想在XAML中像在{p>中那样使用整数作为CommandParameter

 <MenuFlyoutItem Text="Save" Command="{Binding}" CommandParameter="1"/>

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

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

public class CreateAndCopy {
public static void main(String[] args) throws Exception {
    File obj2 = new File("abc.txt");
    Scanner obj1 = new Scanner(System.in);
    PrintWriter testing = new PrintWriter(obj2);
    int x = obj1.nextInt();
    int y = obj1.nextInt();
    int z = obj1.nextInt();
    testing.println(x);
    testing.println(y);
    testing.println(z);
    testing.close();
    System.out.println("");
    }
}