【发布时间】:2023-03-04 21:13:01
【问题描述】:
我正在尝试在 Xml 中绑定手势识别器,以便在单击项目时进行处理
我尝试将它用于我的 XML
<DataTemplate x:Key="TextPostTemplate">
<ViewCell>
<StackLayout BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 10, 10">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}" TextColor = "Black" FontSize = "15"/>
<Image Source="options_icon.png" HeightRequest="15" HorizontalOptions="EndAndExpand" Margin="0, 0, 10, 0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="{Binding OptionClick}"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
<Label Text="{Binding Body}" TextColor = "Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
我尝试将其绑定到
foreach (var post in posts)
{
TapGestureRecognizer optionsClick = new TapGestureRecognizer();
optionsClick.Tapped += (s, e) =>
{
ShowPostOptions(page, navigation, post.id, post.user);
};
}
还有……
OptionClick = optionsClick
但我明白了
.xaml:错误:无法将“Xamarin.Forms.Xaml.ElementNode”类型的对象转换为“Xamarin.Forms.Xaml.ValueNode”类型。
【问题讨论】:
标签: c# xml xaml xamarin xamarin.forms