您的位置:首页 > 其它

WP8__实现ListBox横向滑动及子项绑定图片等控件

2014-06-18 22:27 645 查看
[code]<!--实现绑定的图片等信息ListBox水平滚动-->
<Grid>
<Grid.Resources>
<Stylex:Key="horizontalListBoxStyle"TargetType="ListBox">
<SetterProperty="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanelOrientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<ListBoxHeight="auto"Name="imglist1"HorizontalContentAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
Style="{StaticResourcehorizontalListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinitionHeight="auto"></RowDefinition>
<RowDefinitionHeight="60"></RowDefinition>
<RowDefinitionHeight="*"></RowDefinition>
</Grid.RowDefinitions>
<ImageName="imgShow"Source="{BindingPath}"Tag="{BindingId}"Grid.Row="0"Width="420"Height="400"Margin="30,30,30,30"Stretch="Fill"MouseLeftButtonUp="imgShow_MouseLeftButtonUp"></Image>
<StackPanelOrientation="Horizontal"VerticalAlignment="Center"Grid.Row="1">
<ButtonName="btnZan"Tag="{BindingId}"Content="赞"Height="70"Width="150"FontSize="26"Margin="20,0,10,0"Click="btnZan_Click"></Button>
<ButtonName="btnCai"Tag="{BindingId}"Content="踩"Height="70"Width="150"FontSize="26"Margin="10,0,20,0"Click="btnCai_Click"></Button>
</StackPanel>
<GridGrid.Row="2"></Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>


实现:
即将跳转到页面A,在页面A中有一个listbox,在跳转的时候,接收参数,自动选中listbox中的某项

[code]///<summary>
///接收参数,定位当前选中项
///</summary>
protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.NavigationEventArgsargs)
{
IDictionary<string,string>parameters=this.NavigationContext.QueryString;
if(parameters.ContainsKey("Id"))
{
stringid=parameters["Id"];//图片Id
intindex=0;
for(inti=0;i<imglist1.Items.Count;i++)
{
//ImgInfoBase为listbox的Item项;imglist1.ItemsSource=(List<ImgInfoBase>)...
ImgInfoBaseitem=(ImgInfoBase)imglist1.Items[i];
if(item.Id==id)
{
index=i;
break;
}
}
if(imglist1.Items.Count>index)
{
UpdateLayout();
imglist1.SelectedIndex=index;//使listbox滚动到指定的位置项上
//imglist1.ScrollIntoView(imglist1.Items[index]);
}
}
base.OnNavigatedTo(args);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐