Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ListView: Icons view shown in a single column
    primarykey
    data
    text
    <p>I'm experiencing a weird problem...</p> <p>What I'm trying to do is quite standard, I guess: aloowing the user to switch between Grid and Icon modes in my ListView. All is going well, but... The Icon view, instead of showing the items in wrapping rows, shows them in a single column, with each item occupying the whole width of the view. And I can't put my finger on what exactly is wrong... :-(</p> <p><em>(I haven't earned enough XP on this forum yet, and it won't allow me to post images; I'll give the links to the screenshots instead)</em></p> <p>What I want: <a href="http://i.stack.imgur.com/jYhVx.png" rel="nofollow">http://i.stack.imgur.com/jYhVx.png</a></p> <p>What I have: <a href="http://i.stack.imgur.com/PeAae.png" rel="nofollow">http://i.stack.imgur.com/PeAae.png</a></p> <p>Here's the IconView style definition (in Themes\Generic.xaml):</p> <pre><code>&lt;Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type l:IconView}, ResourceId=IconViewStyle}" TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}"&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Center"/&gt; &lt;Setter Property="ItemContainerStyle" Value="{Binding (ListView.View).ItemContainerStyle, RelativeSource={RelativeSource Self}}"/&gt; &lt;Setter Property="ItemTemplate" Value="{Binding (ListView.View).ItemTemplate, RelativeSource={RelativeSource Self}}"/&gt; &lt;Setter Property="ItemsPanel"&gt; &lt;Setter.Value&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel IsItemsHost="True" Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}" MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}" ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>It's used in the corresponding Control class:</p> <pre><code>public class IconView : ViewBase { public static readonly DependencyProperty ItemContainerStyleProperty = ItemsControl.ItemContainerStyleProperty.AddOwner(typeof(IconView)); public Style ItemContainerStyle { get { return (Style)GetValue(ItemContainerStyleProperty); } set { SetValue(ItemContainerStyleProperty, value); } } public static readonly DependencyProperty ItemTemplateProperty = ItemsControl.ItemTemplateProperty.AddOwner(typeof(IconView)); public DataTemplate ItemTemplate { get { return (DataTemplate)GetValue(ItemTemplateProperty); } set { SetValue(ItemTemplateProperty, value); } } public static readonly DependencyProperty ItemWidthProperty = WrapPanel.ItemWidthProperty.AddOwner(typeof(IconView)); public double ItemWidth { get { return (double)GetValue(ItemWidthProperty); } set { SetValue(ItemWidthProperty, value); } } public static readonly DependencyProperty ItemHeightProperty = WrapPanel.ItemHeightProperty.AddOwner(typeof(IconView)); public double ItemHeight { get { return (double)GetValue(ItemHeightProperty); } set { SetValue(ItemHeightProperty, value); } } protected override object DefaultStyleKey { get { return new ComponentResourceKey(GetType(), "IconViewStyle"); } } } </code></pre> <p>And here's how all this is being used in the View.xaml (I'll omit the DataTrigger that assigns {DynamicResource IconView} to ListView's View, for brevity) :</p> <pre><code>&lt;DataTemplate x:Key="IconViewItemTemplate"&gt; &lt;StackPanel Height="170" Width="170"&gt; &lt;Grid Width="150" Height="150" HorizontalAlignment="Center"&gt; &lt;Image Source="{Binding DefaultPicture.Path}" Margin="6,6,6,9"/&gt; &lt;/Grid&gt; &lt;TextBlock Text="{Binding ID}" FontSize="13" HorizontalAlignment="Center" Margin="0,0,0,1" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;localControls:IconView x:Key="IconView" ItemTemplate="{StaticResource IconViewItemTemplate}" ItemWidth="180"/&gt; </code></pre> <p>I am going nuts... And, to add to my frustration, Snoop doesn't see my application :-(</p> <p>Please help! ;-)</p> <p>Many thanks, Alex</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload