I need to create a horizontal list view for a Windows Store application with full screen image items, something like the Gallery control for Android. To do this, I've used a GridView
and changed the ItemsPanel
template to be a VirtualizingStackPanel
with horizontal orientation. The problem is that I cannot make the Image items to be full screen. What I've tried is to make the GridView.ItemContainerStyle
to bind to the GridView
's width, like this:
Binding widthBinding = new Binding() { Source=iconsHolder, Path = new PropertyPath("Width"), Converter = new TestItemWidthConverter()};
Style itemStyle = new Style();
itemStyle.TargetType = typeof(GridViewItem);
itemStyle.Setters.Add(new Setter(GridViewItem.WidthProperty, widthBinding));// 800));
iconsHolder.ItemContainerStyle = itemStyle;
When I replace the widthBinding
with 800, for example, the icons have the specified width, but when I use the binding, no items are visible, so the Style
do its job, but the Binding
has a problem. In order to debug this, I've created a fake converter, so I can see if the binding works, but the Convert(..) method isn't called at all.
My GridView is created like this:
GridView iconsHolder = new GridView();
iconsHolder.ItemsPanel = App.Current.Resources["HorizontalVSPTemplate"] as ItemsPanelTemplate;
iconsHolder.ItemTemplate = App.Current.Resources["MyDataTemplate"] as DataTemplate;
iconsHolder.Width = Window.Current.Bounds.Width;
iconsHolder.Height = Window.Current.Bounds.Height;
and my resources are defined like:
<ItemsPanelTemplate x:Key="HorizontalVSPTemplate">
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="MyDataTemplate">
<Image Source="some irrelevant url here"/>
</DataTemplate>
My converter looks like this:
public sealed class TestItemWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Debug.WriteLine(" binding width=" + value);
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{ return value; }
}
I don't know how to achieve this (I've also tried using RelativeBinding
or make Icons to be horizontally stretched, without success) or what I'm doing wrong, so please help! Thank you for your time!
I've figure it out that I was on the wrong path, the right way to do it was to use FlipView
, just as simple as
FlipView iconsHolder = new FlipView();
iconsHolder.ItemsSource = myItems;
iconsHolder.ItemTemplate = App.Current.Resources["MyDataTemplate"] as DataTemplate;
이제 내 아이콘은 기본적으로 전체 화면이며 스크롤 효과가 페이지로 표시됩니다. 이 컨트롤에 대한 몇 가지 유용한 세부 정보는 빠른 시작 : FlipView 컨트롤 추가 에서 찾을 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다