【发布时间】:2016-11-26 22:06:53
【问题描述】:
目前我有一个自定义 ViewCell,其模板选择器绑定到 ObservableCollection。 我已将自定义单元格模板绑定到我的 Xamarin.Forms IOS ListView。
我的问题是我无法禁用所选项目的突出显示,只有当我通过 MenuContext Actions 复制所选项目时才会出现灰色...
我已经尝试了我在 Internet 上找到的每个自定义渲染器
也许我使用了错误的自定义渲染器。我需要一个渲染器来解决这个问题吗?
ViewCellRenderer
[assembly: ExportRenderer(typeof(GerätViewCell), typeof(NativeViewCellRenderer))]
namespace LindeXF.iOS.Renderer {
public class NativeViewCellRenderer : ViewCellRenderer {
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) {
var cell = base.GetCell(item, reusableCell, tv);
if (cell != null)
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
return cell;
}
}
}
自定义 ViewCell
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LindeXF.Core.CustomTemplates.GerätViewCell"
>
<ViewCell.ContextActions>
<MenuItem x:Name="MenuItemDuplizieren"
CommandParameter="{Binding Id}"
Clicked="OnDuplizierenClicked"
Text="Duplizieren" />
<MenuItem x:Name="MenuItemLöschen"
CommandParameter="{Binding Id}"
Clicked="OnLöschenClicked"
Text="Löschen"
IsDestructive="True" />
</ViewCell.ContextActions>
<Grid ColumnSpacing="0" BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="18*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="{Binding BoxColor}" Grid.Column="0"/>
<Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="1"/>
<Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="2"/>
<Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="3"/>
<Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="4"/>
<Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="5"/>
<Label FontSize="14" HorizontalTextAlignment="End" Margin="0,0,5,0" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="6"/>
<Label FontSize="14" HorizontalTextAlignment="End" Margin="0,0,5,0" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="7"/>
</Grid>
</ViewCell>
列表视图
<ListView x:Name="ListViewKalkulation"
Margin="1,0,1,1"
ItemTapped="ListViewKalkulationText_OnItemTapped"
ItemTemplate="{StaticResource TemplateSelector}"
ChildAdded="ListViewKalkulation_OnChildAdded"
ItemSelected="ListViewKalkulation_OnItemSelected"
SeparatorVisibility="None"
BackgroundColor="Silver"
Grid.Row="1" />
感谢您的宝贵时间!
【问题讨论】:
-
您好,也许您提供了有关该问题的更多信息,很高兴提及您为什么要自定义渲染您的视单元。一个用例场景会很好:)
-
Hej,对不起,我认为问题很清楚 :) 我只想在与 Listview 项目交互时禁用它们的突出显示(不会去的丑陋的灰色)我在想也许这是不可能的,因为我使用视图单元作为我的 Listview 项目
标签: c# listview xamarin.ios xamarin.forms