小编Joh*_*eer的帖子

在后面的代码中设置 Xamarin.Forms 绑定 CommandParameter

我正在尝试TapGestureRecognizer在代码上设置绑定,但我无法找到正确的方法。工作的 xaml 看起来像这样......

<Grid>
    <Grid.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding LaunchLocationDetailsCommand}" 
                              CommandParameter="{Binding}" />
    </Grid.GestureRecognizers>
</Grid>
Run Code Online (Sandbox Code Playgroud)

在 C# 中,它看起来像这样......

var gridTap = new TapGestureRecognizer();

gridTap.SetBinding(TapGestureRecognizer.CommandProperty, 
                   new Binding("LaunchLocationDetailsCommand"));

gridTap.SetBinding(TapGestureRecognizer.CommandParameterProperty, 
                   new Binding(/* here's where I'm confused */));

var grid = new Grid();
grid.GestureRecognizers.Add(gridTap);
Run Code Online (Sandbox Code Playgroud)

我的困惑来自CommandParameterProperty. 在 xaml 中,这只是{Binding}没有其他参数。这是如何在代码中完成的?传入new Binding()this.BindingContext似乎不起作用。

c# code-behind xamarin xamarin.forms

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

标签 统计

c# ×1

code-behind ×1

xamarin ×1

xamarin.forms ×1