我在Windows Phone 8上使用LongListSelector控件,无法找出处理项目点击的最佳方法.我发现的几个例子都依赖于SelectionChanged事件.但是,此解决方案有问题,因为如果我点击打开新页面的项目,回击,然后再次点击相同的项目,它将无法工作,因为此项目已被选中,因此不会触发SelectionChanged.
我尝试注册到点击事件并使用当前所选项目作为点击事件,但有时候当前所选项目不是我期望的项目.
我可以将我的ItemTemplate包装在一个按钮中并处理每个项目的点击,但我需要重新设置按钮以使其看起来像一个简单的列表项.
最后,我不明白为什么实现这样一个基本的东西是如此复杂.我错过了一种简单而标准的方式吗?
我的第二个愿望是在点击项目时对项目产生影响.有没有标准的方法呢?
我正在尝试从silverlight工具包LongListSelector创建一个后代类.我们称之为SimpleLonglistSelector.我从"Silverlight for Windows Phone Toolkit Source&Sample - Feb 2011.zip"开始
http://silverlight.codeplex.com/releases/view/60291
我创建了一个新类:
public class SimpleLongListSelector : LongListSelector
{
public SimpleLongListSelector()
{
var itemsPanelTemplate = @"
<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<toolkit:WrapPanel xmlns:toolkit='clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit' Orientation=""Horizontal""/>
</ItemsPanelTemplate>";
this.GroupItemsPanel = (ItemsPanelTemplate)XamlReader.Load(itemsPanelTemplate);
var groupItemTemplate = @"
<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<Border Width=""99"" Height=""99"" Background=""{StaticResource PhoneAccentBrush}"" Margin=""6"" IsHitTestVisible=""{Binding HasItems}"">
<TextBlock Text=""{Binding Key}""
FontFamily=""{StaticResource PhoneFontFamilySemiBold}""
FontSize=""36""
Margin=""{StaticResource PhoneTouchTargetOverhang}""
Foreground=""{StaticResource PhoneForegroundBrush}""
VerticalAlignment=""Bottom""/>
</Border>
</DataTemplate>";
this.GroupItemTemplate = (DataTemplate)XamlReader.Load(groupItemTemplate);
var groupHeaderTemplate = @"
<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<Border Background=""Transparent"">
<Border Background=""{StaticResource PhoneAccentBrush}"" Width=""75"" Height=""75"" HorizontalAlignment=""Left"">
<TextBlock Text=""{Binding Path=Key}"" …
Run Code Online (Sandbox Code Playgroud) inheritance silverlight-toolkit windows-phone-7 longlistselector
我正在使用listbox和wrappanel来显示数据.
例如:
<ListBox ItemTemplate="{StaticResource ItemTemplateListBoxAnimation}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel ItemHeight="150" ItemWidth="150">
</toolkit:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<DataTemplate x:Key="ItemTemplateListBoxAnimation">
<Grid Width="130" Height="130">
<Image Source="{Binding Image}"/>
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
它看起来像:
现在我需要使用LongListSelector和分组结果:
<toolkit:LongListSelector ItemTemplate="{StaticResource ItemTemplateListBoxAnimation}">
<toolkit:LongListSelector.GroupItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</toolkit:LongListSelector.GroupItemsPanel>
</toolkit:LongListSelector>
Run Code Online (Sandbox Code Playgroud)
但它看起来像:
我需要得到:
你的假设?谢谢
xaml wrappanel windows-phone-7 windows-phone longlistselector
如果您将Windows Phone模拟器或设备放入日语,韩语或其他非拉丁语言并使用人员应用程序,则它们的LongListSelector实现会显示日语分组字符,然后是unicode"globe with meridians"字符,后跟az字符:
使用Windows Phone工具包中的LongListSelector,您必须执行自己的手动分组逻辑.如何获取日语/韩语/等名称分组字符列表以及如何确定名称所属的分组字符(因为查看我的第二个屏幕截图,分组字符在用户名中没有)?
我正在使用LongListSelector来实现我的项目的列表或网格显示.为此,我创建了一个DataTemplateSelector,并在运行时更改了LayoutMode属性.这是有效的,但DataTemplateSelector似乎存在问题.如果我最初启动页面,则会为我的三个项目调用DataTemplateSelector三次.当我导航到另一个页面(更改LayoutMode的设置页面)然后返回时,DataTemplateSelector只被称为两个项目,但仍然有三个项目.
DataTemplateSelector:
public abstract class DataTemplateSelector : ContentControl
{
public virtual DataTemplate SelectTemplate(object item, DependencyObject container)
{
return null;
}
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
ContentTemplate = SelectTemplate(newContent, this);
}
}
Run Code Online (Sandbox Code Playgroud)
ItemViewModeTemplateSelector:
public class ItemViewModeTemplateSelector: DataTemplateSelector
{
public DataTemplate ListViewModeTemplate
{
get;
set;
}
public DataTemplate GridViewModeTemplate
{
get;
set;
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
ViewMode viewMode = ViewMode.Grid;
// Get ViewMode from IsolatedStorageSettings...
switch (viewMode)
{
case ViewMode.Grid:
return GridViewModeTemplate; …
Run Code Online (Sandbox Code Playgroud) c# datatemplateselector windows-phone longlistselector windows-phone-8
在工具包 LongListSelector中,曾经有一个属性IsFlatList需要设置为true才能显示平面列表而不进行任何分组.但是在手机控件中提供的LongListSelector中,缺少此属性.这就是我在做的事情
<phone:LongListSelector Name="myList" IsGroupingEnabled="False" LayoutMode="List" ItemsSource="{Binding Source ={StaticResource SortedList} }" CacheMode="BitmapCache" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<components:MyControl CacheMode="BitmapCache" MyItem="{Binding}"/>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Run Code Online (Sandbox Code Playgroud)
如果我将控件更改为ListBox并删除LongListSelector特定属性,那么它将显示我的列表.
有人可以告诉我我错过了什么吗?我正在关注LongListSelector的这个(备注)文档
在WP8中,他们忘了将SelectedItem作为依赖属性提供,因此我无法绑定它.我使用此修复了:http://dotnet-redzone.blogspot.com/2012/11/windows-phone-8longlistselector.html
在这样做时,我注意到我无法从ViewModel重置属性,即如果我在ViewModel中将项目设置为null,则它不会影响UI.我已经在UI中提供了双向绑定,但仍然在ViewModel中将项设置为null不会更改LongListSelector中的选定项.我也不想使用SelectionChanged事件,因为我在WP7.5应用程序和WP8应用程序之间共享ViewModel,因此我想尽可能多地推送到ViewModel中.这有解决方案吗?
随着Windows Phone Toolkit的最新更新,他们对Mango版本的LongListSelector的内部进行了全面检查.其中一个更改是删除对该GetItemsInView()
函数的支持(它现在返回一个空列表).此功能先前返回了当前在屏幕上可见的项目列表.当我离开页面时,我正在使用它来获取对最顶层可见项的引用,以便我可以通过使用支持在墓碑之后恢复ScrollTo(object item)
.
有谁知道建议的替代方案是什么?我知道,芒果墓碑不是一个问题,但我仍然想支持它,并且可能还有其他一些场景,我想要回想起滚动位置.在某些情况下,我的列表包含数千个项目.
silverlight-toolkit windows-phone-7 windows-phone-7.1 longlistselector
在WP7中,LongListSelector有一个底层的ScrollViewer,我可以从中恢复列表的垂直偏移量.但是在Windows Phone 8中,没有底层的ScrollViewer,也没有任何类似的类为我提供了VerticalOffset属性.
我一直在寻找,没有找到任何东西.我可以使用一个函数来解决列表中的第一个可见元素,但我也没有找到任何东西.ItemRealized事件对此没有用,因为它没有给出在视口顶部显示的确切项目.
我有一个longlistselector与我在这个longlistselector中添加的某些图像.我还更改了此图像的边距以使图像上下移动等等.但我想把这张图片放在这个longlistselector的另一张图片的前面.我尝试过使用Canvas.Zindex.我已经尝试在网格级别,图像级别和longlistselector的顶层设置它.()但它仍然无效.有人有想法吗?您可以在下面找到我的代码:
<phone:LongListSelector
x:Name="SouthLongListselector"
VerticalAlignment="Bottom"
ItemsSource="{Binding Cards}"
Canvas.ZIndex="{Binding Layer}"
SelectionChanged="SouthLongListselector_SelectionChanged"
LayoutMode="Grid"
GridCellSize="50,200"
Margin="0,0,0,-26"
>
<phone:LongListSelector.ItemTemplate >
<DataTemplate>
<Grid
Background="Transparent"
Margin="{Binding GridOffset}"
Height="150"
Width="110"
>
<!-- add image here-->
<Image
Source="{Binding Image}"
>
</Image>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Run Code Online (Sandbox Code Playgroud)
提前致谢,
longlistselector ×10
c# ×3
xaml ×3
canvas ×1
datatemplate ×1
inheritance ×1
wrappanel ×1
z-index ×1