我试图模仿像Windows Phone 8.1中的Messaging应用程序一样的ListView行为,但我似乎无法理解它。
到目前为止,我的XAML是:
<ListView ItemsSource="{Binding}"
ItemTemplate="{StaticResource dataTemplate}"
Name="characterListView"
SelectionChanged="CharacterListView_OnSelectionChanged"
SelectionMode="Multiple"
ItemClick="CharacterListView_OnItemClick"
IsItemClickEnabled="False">
</ListView>
背后的代码是:
private void CharacterListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (characterListView.SelectedItems.Count > 0)
{
characterListView.SelectionMode = ListViewSelectionMode.Multiple;
}
else
{
//characterListView.ItemClick -= CharacterListView_OnItemClick;
characterListView.SelectionMode = ListViewSelectionMode.Single;
}
}
private void CharacterListView_OnItemClick(object sender, ItemClickEventArgs e)
{
Frame.Navigate(typeof (PivotPage), e.ClickedItem);
}
这个想法基本上是:如果没有选择任何项目,则使用点击的项目作为参数导航到页面。点击项目左侧应激活多选,并禁用导航。 (我在appbar上有另一个多选的计划,但这是另一个故事)。好吧......就像消息传递应用程序一样!
我知道这个组件:https://modernography.wordpress.com/2014/08/28/multiselectlistview_with_edge_action/这很好,但无论如何我无法让它完全正常工作。我已经摆弄了几个星期和nada。
答案 0 :(得分:0)
我回到使用带有Edge Action组件的MultiSelectView并设法获取示例或源代码。基于此,我打算这样做:
<q:MultiSelectListView
ItemsSource="{Binding}"
ItemTemplate="{StaticResource dataTemplate}"
IsItemClickEnabled="True"
ItemClick="CharacterListView_OnItemClick"
Name="characterListView"
SelectionChanged="CharacterListView_OnSelectionChanged"
SelectionModeChanged="CharacterListView_OnSelectionModeChanged"
>
</q:MultiSelectListView>
代码背后:
private void CharacterListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
characterListView.SelectionMode = characterListView.SelectedItems.Count == 0 ?
ListViewSelectionMode.None : ListViewSelectionMode.Multiple;
}
private void CharacterListView_OnSelectionModeChanged(object sender, RoutedEventArgs e)
{
if (characterListView != null)
{
characterListView.IsItemClickEnabled = characterListView.SelectionMode != ListViewSelectionMode.Multiple;
}
}
private void CharacterListView_OnItemClick(object sender, ItemClickEventArgs e)
{
Frame.Navigate(typeof (CharacterPage), e.ClickedItem);
}