Programmatically create a GridView with full screen items

Bianca Daniciuc

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!

Bianca Daniciuc

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to create a full screen window on the current monitor with GLFW

분류에서Dev

Full screen in virtualbox

분류에서Dev

Centered, Full Screen Application

분류에서Dev

Full-screen adaptive video

분류에서Dev

Captions only working in full screen

분류에서Dev

Full screen view in LibreOffice Draw?

분류에서Dev

Flash content not go full screen

분류에서Dev

HTML & CSS - Full Screen Image

분류에서Dev

Should my Dash be full screen?

분류에서Dev

create xml with attributes programmatically

분류에서Dev

GridView items not displaying correct images or backgrounds

분류에서Dev

How make android Gridview items clickable

분류에서Dev

Create Startup Screen

분류에서Dev

Create new UI elements programmatically

분류에서Dev

Chrome in Linux Ubuntu stays in Full screen mode

분류에서Dev

Run exe file on full screen mode game

분류에서Dev

Full screen gvim window manager limitations on Ubuntu

분류에서Dev

JVectorMap Scroll Speed and Full screen Issue

분류에서Dev

Full screen video tearing in firefox Ubuntu 19.04

분류에서Dev

White blocking screen when put youtube in full-screen mode

분류에서Dev

Qemu top panel (which contains the "Exit full screen" button) doesn't appear in full screen

분류에서Dev

ASP.NET LinkButton in GridView causing full postback

분류에서Dev

jquery-chosen Dropdown is not populated when all Gridview items are deleted

분류에서Dev

SSIS: generate create table DDL programmatically

분류에서Dev

Drupal 7 create and send mailchimp campaign programmatically

분류에서Dev

SQL Web Replication, Create New Subscription Programmatically

분류에서Dev

Intersystems caché - programmatically create new class

분류에서Dev

How to make emacs truly full screen on start up?

분류에서Dev

Receiving hidden status bar/entering a full screen activity event on a Service

Related 관련 기사

뜨겁다태그

보관