Я пытаюсь реализовать пользовательский режим просмотра для ListView
, описанного здесь , но безуспешно: WrapPanel
и ItemTemplate
представления не применяются. И нет полного кода, поэтому я не знаю, как создать объект списка. Вот полный код из приведенного выше примера:
<Window.Resources>
<Style x:Key="{ComponentResourceKey
TypeInTargetAssembly={x:Type local: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={RelativeSource Self}}"/>
<Setter Property="ItemTemplate"
Value="{Binding (ListView.View).ItemTemplate,
RelativeSource={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 (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="centralTile">
<StackPanel Height="100" Width="90">
<TextBlock Text="{Binding}" FontSize="13"
HorizontalAlignment="Center" Margin="0,0,0,1" />
<TextBlock Text="{Binding}" FontSize="9"
HorizontalAlignment="Center" Margin="0,0,0,1" />
</StackPanel>
</DataTemplate>
<local:PlainView x:Key="tileView"
ItemTemplate="{StaticResource centralTile}"
ItemWidth="100"/>
</Window.Resources>
<Grid>
<ListView x:Name="lv" ItemsSource="{Binding Entries}" />
</Grid>
.cs
public class ViewModel
{
public ObservableCollection<string> Entries { get; private set; }
public ViewModel()
{
Entries = new ObservableCollection<string>();
Entries.Add("one");
Entries.Add("two");
Entries.Add("three");
Entries.Add("four");
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new ViewModel();
lv.View = lv.FindResource("tileView") as ViewBase;
}
}
Чего мне не хватает?