【发布时间】:2018-11-26 21:52:52
【问题描述】:
我发现 this GitHub 帖子显示了一个方便的 Xamarin DataGrid。但是,我想更进一步,在最左边的列中添加一个复选框,这样我就可以单击按钮从已选择的网格中捕获所有 ID。
这在Xamarin.Forms 和C# 中可以实现吗?
编辑
因此,经过大量谷歌搜索后,我发现使用“切换”会更容易,并且我的 XAML 有此代码。我的问题是如何将我的数据库字段绑定到标签的绑定?
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.Pages.TestApprove" >
<ContentPage.Content>
<StackLayout>
<Label Text="The users below are Requesting Access:"></Label>
<Grid Padding="5,0" RowSpacing="1" ColumnSpacing="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Switch Grid.Row="0" Grid.Column="0" VerticalOptions="Center"
HorizontalOptions="Center" BackgroundColor="Brown" />
<Label Text="{Binding fname}" Grid.Row="0" Grid.Column="1"
Grid.ColumnSpan="1" Margin="1"
BackgroundColor="Blue" IsEnabled="false"/>
<Entry Text="{Binding lname}" Grid.Row="0" Grid.Column="2"
Grid.ColumnSpan="1" Margin="1" IsEnabled="false"
FontSize="Small" BackgroundColor="Purple" />
<Entry Text="{Binding company}" Grid.Row="0" Grid.Column="3"
Grid.ColumnSpan="1" Margin="1"
FontSize="Small" BackgroundColor="Green" />
<Entry Text="{Binding Phone}" Grid.Row="0" Grid.Column="4"
Grid.ColumnSpan="1" Margin="1"
FontSize="Small" BackgroundColor="Orange" />
</Grid>
<Button Command="{Binding ApproveUserCommand}" Text="Approve User" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
当然,我想动态生成选择查询返回的行数……所以如果有 10 个用户请求访问,我应该是每个用户数据的 10 行。我是否以正确的方式解决这个问题/。如何绑定数据?
【问题讨论】:
-
可以实现吗?当然。但是目前还没有内置的复选框控件,因此您必须自己构建/查找(那里有很多示例)。
-
@Jason - 感谢您的建议。我的意思是可以实现我的结果的内置或多合一控件。我会继续进行谷歌搜索,因为我所发现的一切都“完全”是我所追求的:D
-
或者使用像 Syncfusion 等商业网格
-
@Jason - 我是否在正确的方向上使用我链接到的网格并使用我发现的多个复选框之一?还是这样不妥?
-
只要支持在单元格内使用任意控件,我都会这么认为
标签: c# xamarin xamarin.forms datagrid xamarin.ios