eAlex79

Hi!

I enabled themeing my app using the SimpleStyle sample theme from the SDK. Allright, it works okay so far but when I have my custom View in a ListView (items in a WrapPanel) they don't show up next to each other (as files do in the Explorer when in Icon view) but instead they are lined up on top of each other.

I really cannot find ANY property or style in the simple styles that could cause the behaviour. When the app is started without themeing it with SimpleStyles the items show up as they should and as I designed them to do.

I tried to copy the normal generic themes for all parts of the ListView using Blend, and they get applied but still, the items would stack on top of each other instead of wrap around.

Possibly I am just stupid Stick out tongue Could anybody help me out

x
x Alex
x



Re: Windows Presentation Foundation (WPF) ListView behaviour using SimpleStyles Sample theme from SDK

Zhou Yong

Your problem is too specific to construct an answer, some repro code is needed here.

Sheva





Re: Windows Presentation Foundation (WPF) ListView behaviour using SimpleStyles Sample theme from SDK

eAlex79

Hi!

So I guess the SimpleStyles Example code is available to everybody (in WPFSamples/Controls/ControlTemplateExamples/Resources). Here is my View code:

DrawingBrushView.cs

Code Snippet

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Controls;

using System.Windows;

namespace DForum.Controls.ListViews

{

public class DrawingBrushView : ViewBase

{

public static readonly DependencyProperty ScaleProperty =

DependencyProperty.Register("Scale", typeof(double), typeof(DrawingBrushView), new PropertyMetadata(100.0));

public double Scale

{

get { return (double)this.GetValue(ScaleProperty); }

set { this.SetValue(ScaleProperty, value); }

}

protected override object DefaultStyleKey

{

get { return new ComponentResourceKey(GetType(), "DrawingBrushView"); }

}

protected override object ItemContainerDefaultStyleKey

{

get { return new ComponentResourceKey(GetType(), "DrawingBrushViewItem"); }

}

}

}

And here the generic.xaml:

Code Snippet

<ResourceDictionary

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:l="clr-namespace:DForum.Controls.ListViews"

xmlns:tp="clr-namespace:DForum.Controls.Pages"

>

<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type l:DrawingBrushView},ResourceId=DrawingBrushView}"

TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">

<Setter Property="BorderBrush" Value="Black"/>

<Setter Property="BorderThickness" Value="0.5"/>

<Setter Property="Template">

<Setter.Value>

<ControlTemplate>

<Border Name="bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"

Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}">

<ScrollViewer Margin="{TemplateBinding Padding}">

<WrapPanel ItemWidth="150" IsItemsHost="True" MinWidth="100"

Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">

</WrapPanel>

</ScrollViewer>

</Border>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type l:DrawingBrushView},ResourceId=DrawingBrushViewItem}"

TargetType='{x:Type tp:PreviewItem}' BasedOn='{StaticResource {x:Type ListBoxItem}}'>

<Setter Property="Padding" Value="3"/>

<Setter Property="Margin" Value="5"/>

<Setter Property="HorizontalContentAlignment" Value="Center"/>

<Setter Property="ContentTemplate">

<Setter.Value>

<DataTemplate>

<StackPanel>

<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tp:PreviewItem}}, Path=Title}"/>

<Rectangle

Height="{Binding (ListView.View).Scale,

RelativeSource=

{RelativeSource FindAncestor, AncestorType={x:Type ListView}}

}"

Width="{Binding (ListView.View).Scale,

RelativeSource=

{RelativeSource FindAncestor, AncestorType={x:Type ListView}}

}"

Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tp:PreviewItem}}, Path=Brush}"

/>

</StackPanel>

</DataTemplate>

</Setter.Value>

</Setter>

</Style>

</ResourceDictionary>

..which is linked to the app in either case (with the sample styles and without them)

Thx,

x

x Alex.

x






Re: Windows Presentation Foundation (WPF) ListView behaviour using SimpleStyles Sample theme from SDK

eAlex79

oh maybe the code for the items is interesting too. I didn't get it working at all when the items are not relating the listviewitem..

Code Snippet

public class PreviewItem : ListViewItem

{

string title;

public string Title

{

get { return title; }

set { title = value; }

}

string group;

public string Group

{

get { return group; }

set { group = value; }

}

DrawingBrush brush;

public DrawingBrush Brush

{

get { return brush; }

set { brush = value; }

}

public PreviewItem(string title, string group, DrawingBrush brush)

{

this.Title = title;

this.Group = group;

this.Brush = brush;

}

}

public class PreviewItems : ObservableCollection<PreviewItem>

{

}

There is a page in my app that fills an PreviewItems object with brushes, names and group info from a ResourceDictionary.

x

x Alex.

x






Re: Windows Presentation Foundation (WPF) ListView behaviour using SimpleStyles Sample theme from SDK

Yi-Lun Luo - MSFT

Hello, I think the problem is: you may not have applied the correct style. There’s already a style for ListView defined in the SimpleStyles example. To use your own, you should use:

<ListView Style="{DynamicResource {ComponentResourceKey {x:Type l: DrawingBrushView}, DrawingBrushView}}">

Note: there's no space between : and D. I added one to prevent it turning into a face Big Smile.






Re: Windows Presentation Foundation (WPF) ListView behaviour using SimpleStyles Sample theme from SDK

eAlex79

Yes! Big Smile Finally!

Thank you so much!