【发布时间】:2017-12-09 02:29:58
【问题描述】:
我想创建一个 viewcell,其中 stacklayout 包含 Frame 用于每行的边框。此框架包含标签和一个按钮。在此按钮上单击我必须更改屏幕。
当我在 iOS 模拟器上渲染该代码时发现一个问题,发现在选择任何行(即 viewcell)时,它会变灰并显示模糊的选定行,看起来很难看。我试图禁用解决了我的行选择问题的视图单元格,但它也禁用了按钮单击行,因为它是其中的一部分。
我只需要启用一个按钮并可供单击,并且 viewcell 上的其余部分不应该是可单击的或可供选择的。我必须使用框架作为边框。它还提供圆形边框,但建议我一些解决方案,我也可以用它来代替边框。
<ListView x:Name="lstView" RowHeight="150" SeparatorVisibility="None" IsPullToRefreshEnabled="False" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10,10,10,10">
<Frame OutlineColor="Silver">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Label Text="Car Type" Grid.Row="0" Grid.Column="0" FontAttributes="Bold"/>
<Label Text="{Binding CreatedDate}" Grid.Row="1" Grid.Column="0"/>
<Label Text="{Binding TransactionId}" Grid.Row="2" Grid.Column="0"/>
<StackLayout Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<Label Text="Status" FontAttributes="Bold"/>
<Label Text="{Binding Status}" FontAttributes="Bold"/>
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
<Label Text="Customer Name" />
<Label Text="{Binding CustName}" />
</StackLayout>
<Button Text="Button" Grid.Row="1" Grid.Column="2" Clicked="OnClicked" CommandParameter="{Binding DisplayName}"></Button>
</Grid>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
-
您可以在选择时移除listview项目的背景颜色。通过渲染ViewCell并设置
SelectionStyle = UITableViewCellSelectionStyle.None -
这是 xamarin 形式。有什么办法可以在 xamarin 表单上做到这一点。或者请帮助我在渲染器中编写代码。我的目标是尽可能多地使用跨平台,因为我也针对 android 和 windows phone。
-
另外,阿卡什,我只能在 iOS 端的 Cell 中配置 SelectionStyle 属性,而我可以在 Xamarin Forms Xaml 端像上面所做的那样在 Xamarin Forms Xaml 端做吗?