再会!
我花了很长时间来创建自己的 HTPC 应用程序,它基本上允许我简单地浏览和播放我的电影收藏。我编写了另一个小应用程序来索引所有内容并准备一个 XML 文件,其布局如下所示。
一切正常,但现在我想实现一些排序选项。通过按“S”键,我想遍历一些固定的排序方法,例如“按标题”、“按发布日期”、“按流派”……
我的 XAML 是我在网上找到的东西的混搭,不幸的是我不是专家,它显示在凌乱的代码中。它基本上将同人画显示为背景,并在屏幕底部有一个水平滚动条,您可以在其中选择电影(它还将所选电影保持在屏幕中间)。
我将如何解决这个问题?
<MOVIES>
<MOVIE>
<TITLE></TITLE>
<PATH></PATH>
<FANART></FANART>
<COVER></COVER>
<RELEASEDATE></RELEASEDATE>
etc...
</MOVIE>
</MOVIES>
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowState="Maximized" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="350" Width="525" ShowInTaskbar="True" WindowStyle="None" Loaded="Window_Loaded">
<Window.Resources>
<XmlDataProvider x:Key="MovieData"
Source="movies.xml" />
<DataTemplate x:Key="ItemTemplate">
<Image Source="{Binding XPath=COVER}" Width="166" Height="250" Margin="0,0" MaxWidth="166" MaxHeight="250" MinWidth="166" MinHeight="250" Stretch="Fill" />
</DataTemplate>
<DataTemplate x:Key="SelectedItemTemplate">
<Border BorderBrush="WhiteSmoke" BorderThickness="3">
<Image Source="{Binding XPath=COVER}" Width="250" Height="375" Margin="0,0" MaxWidth="250" MaxHeight="375" MinWidth="250" MinHeight="375" Stretch="Fill" />
</Border>
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style />
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedItemTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid DataContext="{Binding Source={StaticResource MovieData}, XPath=/MOVIES/MOVIE}">
<Grid.RowDefinitions>
<RowDefinition Height="178*" />
<RowDefinition Height="133*" />
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="{Binding XPath=FANART}"/>
</Grid.Background>
<ListBox x:Name="Listbox1"
SelectionChanged="ScrollIntoView"
ItemContainerStyle="{StaticResource ContainerStyle}"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
HorizontalAlignment="Center" Grid.Row="1" VerticalAlignment="Bottom" KeyDown="Listbox1_KeyDown">
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border>
<ScrollViewer x:Name="ScrollView1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" VerticalContentAlignment="Bottom" CanContentScroll="True">
<VirtualizingStackPanel x:Name="SPanel1" IsItemsHost="True" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
</ListBox>
</Grid>