Trouble with custom views and ListVIew
Hello,
I have been trying to add a custom view to my listview and for the life of me I can get it to work. I imported most of the code from the ListViewMutlipleView SDK sample, and I cant understand how the whole process works. I am attaching my project code. The relevant pieces are ImportDialog.xaml, ImportDialog.xaml.cs, PlainView.cs, and General.xaml. ImportDialog.xaml.cs implements the startup window. In the constructer it makes a call to ChangeView() (located at the bottom of the file) which makes the call to load the custom view. The Custom view code comes directly from the SDK sample with no modifications except the namespace. The xaml for general.xaml come mostly from the SDK sample with some editing for namespace and deletion of the views I do not want.
I have tried everything I know, but here is what I know for sure. When I call
PictureList.View = PictureList.FindResource(
"tileView")asViewBase;
the PlainView Object is created. The last method that is called by the framework is
protectedoverrideobject DefaultStyleKey
method. But instead of the correct WrapPanel, and the StackPanel as the ItemTemplate, all I get is some sort of default view. I have tried everythin I know how.
Here is the xaml for the ListView:
<ListView Margin="0,0,0,0" Name="PictureList" HorizontalContentAlignment="Stretch"VerticalContentAlignment="Stretch"</ListView>ItemsSource="{Binding Source={StaticResource PictureList}}"
SelectionMode="Single">
Here is Window resource for ImageDialog.xaml
<Window.Resources><l:PictureCollection x:Key="PictureList"/><DataTemplate x:Key="centralTile">
<StackPanel Height="120" Width="90">
<Grid Width="70" Height="70" HorizontalAlignment="Center">
<Image Source="{Binding Path=FileName}" Margin="6,6,6,9"/></Grid><TextBlock Text="{Binding Path=FileName}" FontSize="13" HorizontalAlignment="Center"
<CheckBox /></StackPanel></DataTemplate>Margin="0,0,0,1" />
<l:PlainView x:Key="tileView" ItemTemplate="{StaticResource centralTile}" ItemWidth="100"/>
</Window.Resources>
Here is teh xaml in General.xaml
<
ResourceDictionaryxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:l="clr-namespace
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type l:PlainView}, ResourceId=myPlainViewDSK}"TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}"
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="ItemContainerStyle" Value="{Binding (ListView.View).ItemContainerStyle, RelativeSource=
<Setter Property="ItemTemplate" Value="{Binding (ListView.View).ItemTemplate, RelativeSource={RelativeSource Self}}"/>
{RelativeSource Self}}"/>
<Setter Property="ItemsPanel"><Setter.Value>
<ItemsPanelTemplate>
<WrapPanel 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}}"/>
</ItemsPanelTemplate></Setter.Value></Setter></Style>
</
ResourceDictionary>Here is the code in PlainView.cs
using
System;using
System.Collections.Generic;using
System.Linq;using
System.Text;using
System.Windows;using
System.Windows.Controls;namespace
PictureImporter{
publicclassPlainView :ViewBase
{
public PlainView()
{
}
publicstaticreadonlyDependencyProperty ItemContainerStyleProperty =ItemsControl.ItemContainerStyleProperty.AddOwner(typeof(PlainView));
publicStyle ItemContainerStyle
{
get {return (Style)GetValue(ItemContainerStyleProperty); }
set { SetValue(ItemContainerStyleProperty,value); }
}
publicstaticreadonlyDependencyProperty ItemTemplateProperty =
ItemsControl.ItemTemplateProperty.AddOwner(typeof(PlainView));
publicDataTemplate ItemTemplate
{
get {return (DataTemplate)GetValue(ItemTemplateProperty); }
set { SetValue(ItemTemplateProperty,value); }
}
publicstaticreadonlyDependencyProperty ItemWidthProperty =WrapPanel.ItemWidthProperty.AddOwner(typeof(PlainView));
publicdouble ItemWidth
{
get {return (double)GetValue(ItemWidthProperty); }
set { SetValue(ItemWidthProperty,value); }
}
publicstaticreadonlyDependencyProperty ItemHeightProperty =WrapPanel.ItemHeightProperty.AddOwner(typeof(PlainView));
publicdouble ItemHeight
{
get {return (double)GetValue(ItemHeightProperty); }
set { SetValue(ItemHeightProperty,value); }
}
protectedoverrideobject DefaultStyleKey
{
get
{
returnnewComponentResourceKey(GetType(),"myPlainViewDSK");}
}
}
}
Can someone please point me in the right direction so I can make some progress.
Thanks in advance
Kevin Koenig

