gpt4 book ai didi

c# - 移动列表框项目而不是 "selector bar"

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:48 24 4
gpt4 key购买 nike

1-是否可以移动列表框项而不是“选择器栏”。这样,选择器栏有一个静态位置,但项目会移动。

我想要实现的是类似于这张图片底部的滚动条: http://i.afterdawn.com/storage/pictures/plex_netflix_addon_3.png

2-水平方向的列表框是否是实现示例中的缩略图查看器的适当工具?

3-我想让它在未来的更新中变成动画吗?可能的?

最佳答案

下面的代码实现了 1 和 2。水平列表框中间的项目总是被选中。列表框需要一些样式才能看起来不错,比如使用不透明度来显示显示哪些项目,哪些项目不显示。

XAML:

<Window x:Class="FlowListTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<ListBox
ItemsSource="{Binding Path=Items}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.ScrollChanged="OnScrollChanged"
SelectionChanged="OnSelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="10" BorderBrush="Red" BorderThickness="2">
<TextBlock Text="{Binding}" Margin="5" Width="20" Height="100"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>

代码隐藏:

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace FlowListTest
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();

DataContext = this;
}

public IEnumerable<string> Items
{
get
{
for (int i = 0; i < 100; i++)
{
yield return i.ToString();
}
}
}

private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
(sender as ListBox).SelectedIndex = _selectedIndex;
}

private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
{
_selectedIndex = (int)(e.HorizontalOffset + Math.Truncate(e.ViewportWidth / 2));
(sender as ListBox).SelectedIndex = _selectedIndex;
}

private int _selectedIndex;
}
}

关于c# - 移动列表框项目而不是 "selector bar",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3192569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com