【发布时间】:2014-12-26 18:51:01
【问题描述】:
我正在使用 Xamarin.Forms 和 XAML,并且正在尝试创建一个存储产品列表的应用程序。我将我的产品列表放在 ListView 中。这工作正常。这是我的 XAML:
<ListView x:Name="listSushi"
ItemsSource="{x:Static local:myListSushi.All}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
RowHeight="{StaticResource rowHeight}"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Padding="5, 5, 0, 5"
Orientation="Horizontal"
Spacing="15">
<StackLayout>
<Image Source="{Binding ImageSource}" />
</StackLayout>
<StackLayout Padding="0, 0, 0, 0"
VerticalOptions="Center"
HorizontalOptions="FillAndExpand">
<Label Text="{Binding Name}"
Font="Bold, Medium" />
<Label Text="{Binding Description}"
Font="Small"/>
</StackLayout>
<StackLayout Orientation="Horizontal"
Padding="0, 0, 10, 0">
<Button Text=" - "
HorizontalOptions="EndAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding DeleteSushiCommand}"
CommandParameter="{Binding Name}"
/>
<Label VerticalOptions="Center"
Text="{Binding Number,StringFormat='{0}'}"
TextColor="Black"/>
<Button Text=" + "
HorizontalOptions="EndAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding AddSushiCommand}"
CommandParameter="{Binding Name}"
/>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
我的问题是,如果我单击 listView 的一个单元格,该单元格会突出显示,并保持突出显示。我尝试在 xaml.cs 中使用此代码禁用它
listSushi.ItemSelected+= (object sender, SelectedItemChangedEventArgs e) => {
// don't do anything if we just de-selected the row
if (e.SelectedItem == null) return;
// do something with e.SelectedItem
((ListView)sender).SelectedItem = null; // de-select the row
};
但是当我触摸一个单元格时,现在我的列表会自动滚动。很奇怪。
有谁知道这是否是一个错误,或者知道一个修复方法,比如是否有一个属性可以禁用突出显示?
【问题讨论】:
-
如果你接受了我的回答就好了。 ;-)
-
在 v3.1 中添加了对禁用 ListView 选择的 API 支持,有关详细信息,请参阅下面的 Jesse 的answer。
标签: xamarin xamarin.forms