diff --git a/Wpf_AiSportsMicrospace/Home.xaml b/Wpf_AiSportsMicrospace/Home.xaml index 0d118df..d54726a 100644 --- a/Wpf_AiSportsMicrospace/Home.xaml +++ b/Wpf_AiSportsMicrospace/Home.xaml @@ -1,9 +1,85 @@ - + Title="CoverFlow Demo" Height="400" Width="800"> + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/Wpf_AiSportsMicrospace/Home.xaml.cs b/Wpf_AiSportsMicrospace/Home.xaml.cs index d8e1c07..1938d41 100644 --- a/Wpf_AiSportsMicrospace/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Home.xaml.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,12 +20,85 @@ namespace Wpf_AiSportsMicrospace /// /// Home.xaml 的交互逻辑 /// - public partial class Home : Page - { + public partial class Home : Window + { + // 所有图片 + public ObservableCollection AllImages { get; set; } = new ObservableCollection(); + public ObservableCollection VisibleImages { get; set; } = new ObservableCollection(); + + private int selectedIndex = 0; + public Home() { InitializeComponent(); - MyCo.SelectedIndex = 0; + + // 示例图片路径 + string projectRoot = System.IO.Path.Combine(AppContext.BaseDirectory, @"..\..\.."); + string albumPath = System.IO.Path.Combine(projectRoot, "Resources", "Img", "Album"); + + string badgePath = System.IO.Path.Combine(projectRoot, "Resources", "Img", "Badge"); + + AllImages.Add(new CoverImage(System.IO.Path.Combine(albumPath, "1.jpg"), System.IO.Path.Combine(badgePath, "1.jpg"))); + AllImages.Add(new CoverImage(System.IO.Path.Combine(albumPath, "2.jpg"), System.IO.Path.Combine(badgePath, "2.jpg"))); + AllImages.Add(new CoverImage(System.IO.Path.Combine(albumPath, "3.jpg"), System.IO.Path.Combine(badgePath, "3.jpg"))); + AllImages.Add(new CoverImage(System.IO.Path.Combine(albumPath, "4.jpg"), System.IO.Path.Combine(badgePath, "4.jpg"))); + AllImages.Add(new CoverImage(System.IO.Path.Combine(albumPath, "5.jpg"), System.IO.Path.Combine(badgePath, "5.jpg"))); + + VisibleImagesControl.ItemsSource = VisibleImages; + + // 默认选中中间图片 + selectedIndex = 2; + UpdateVisibleImages(); + } + private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (sender is Border border && border.DataContext is CoverImage img) + { + int index = AllImages.IndexOf(img); + if (index >= 0) + { + selectedIndex = index; + UpdateVisibleImages(); + } + } + } + + private void UpdateVisibleImages() + { + VisibleImages.Clear(); + for (int offset = -1; offset <= 1; offset++) + { + int idx = selectedIndex + offset; + if (idx >= 0 && idx < AllImages.Count) + { + var img = AllImages[idx]; + img.IsSelected = offset == 0; + VisibleImages.Add(img); + } + } } } + + public class CoverImage : INotifyPropertyChanged + { + public string Path { get; set; } // 主图路径 + public string BadgePath { get; set; } // 小徽章路径 + + private bool _isSelected; + public bool IsSelected + { + get => _isSelected; + set { _isSelected = value; OnPropertyChanged(nameof(IsSelected)); } + } + + public CoverImage(string path, string badgePath = null) + { + Path = path; + BadgePath = badgePath; + } + + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string name) => + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } } diff --git a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml index e393948..1be0c8e 100644 --- a/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml +++ b/Wpf_AiSportsMicrospace/MyUserControl/CoverFlowControl.xaml @@ -4,54 +4,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl" - xmlns:_3DTools="clr-namespace:_3DTools;assembly=3DTools" - Background="Black" x:Name="Root"> + mc:Ignorable="d" + d:DesignHeight="450" d:DesignWidth="800"> - - - - - - - -