如何在 xamarin ContentPage 中的 BindingContext 中设置多个值 [英] How to multiple value in BindingContext in xamarin ContentPage
问题描述
我有 xamarin 应用程序,我需要在按钮单击事件时将两个对象传递给 .cs 文件.
I have xamarin application where I need to pass two objects to .cs file on button click event.
我有两个 ListView 并且在第二个 Listview 项目中有按钮.两个 ListView 都将根据 JSON 动态加载.现在的问题是我需要在按钮单击事件中发送父 ListView 数据源和第二个 ListView 数据源.目前我只能使用 BindingContext 发送一个对象,但我需要将两个或更多对象发送到 .cs 文件.
I have two ListView and have button in inside the 2nd Listview items. Both ListViews will be loaded dynamically based on the JSON. Now the problem is I need to send Parent ListView datasource and second ListView data source in the button click event. currently I am able to send only one using BindingContext but I need to send two or more objects to .cs file.
<ListView x:Name="StaffListMaster_List" RowHeight="150">
<ListView.ItemTemplate>`
<ListView x:Name="Staff_Record" ItemsSource="{Binding Path=detailsobj}">`
<ListView.ItemTemplate>`
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" >
<Button Clicked="OnActionSheetCancelDeleteClicked" BorderRadius="0" BindingContext ="{Binding item}" Text="{Binding item[6]}"/>`
我想在里面获取 StaffListMaster_List 数据源和 Staff_Record 数据源OnActionSheetCancelDeleteClicked(object sender, EventArgs e) {}`
I want to get StaffListMaster_List data source and Staff_Record datasource inside OnActionSheetCancelDeleteClicked(object sender, EventArgs e) {}`
推荐答案
最后我可以解决如下问题:
Finally I am able to solve the issue as follows :
第一步:创建IMultiValueConverter接口第 2 步:创建 MultiBinding.cs 类(参考:[https://gist.github.com/Keboo/0d6e42028ea9e4256715][1] )第 3 步:包含 xmlns:multi="clr-namespace:MultiBindingExample" 命名空间第 4 步:
Step 1 : Create IMultiValueConverter interface Step 2 : created MultiBinding.cs class (ref : [https://gist.github.com/Keboo/0d6e42028ea9e4256715][1] ) Step 3 : Include xmlns:multi="clr-namespace:MultiBindingExample" namespace step 4 :
<Button Command="{Binding ClearListItem}">
<Button.CommandParameter>
<multi:MultiBinding >
<Binding Source="{x:Reference control1}" Path="BindingContext"/>
<Binding Source="{x:Reference control2}" Path="BindingContext"/>
</Button.CommandParameter>
</Button>
第 4 步:在视图模型中
step 4 : In view model
void ClearListViewSelectedItem( object param)
{
var commandParamList = (object[])param;
}
最终的预期结果是.
这篇关于如何在 xamarin ContentPage 中的 BindingContext 中设置多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!