Bla*_*ath 6 wpf xaml itemscontrol scrollviewer uniformgrid
我需要显示位于特定路径中的所有文件.我创建了一个用户控件,其中包含文件详细信息的文本块(名称,大小,扩展名等),此控件将是统一网格的子控件.
问题是,如果我的uniformgrid是5x5,并且我有超过25个文件,则不会显示第26个元素.
我想知道,有没有办法滚动统一网格的内容?
我知道我可以使用列表框和绑定(我还在阅读它),但是我需要以编程方式添加控件,因为控件有一个事件,并且当用户控件的新实例我订阅它时已创建,然后添加到子数组.
我已经看过这篇文章了,我已经将uniforgrid放在了ItemsControl中,但它根本不起作用,这是我的xaml:
<ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" >
<ItemsControl x:Name="gridArchivos">
<ItemsControl.ItemsPanel >
<ItemsPanelTemplate >
<UniformGrid Columns="5" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
根据帖子,只需要指定cols或rows,而不是两者.所以,只有5个小马.我不希望hrizontal滚动,只需垂直.
谢谢你的时间.
我复制了你的Xaml,它似乎按预期工作
这是我的测试代码,它可以帮助您诊断问题
XAML:
<Window x:Class="WpfApplication7.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Name="UI">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" >
<ItemsControl ItemsSource="{Binding Items, ElementName=UI}">
<ItemsControl.ItemsPanel >
<ItemsPanelTemplate >
<UniformGrid Columns="5" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Window>
Run Code Online (Sandbox Code Playgroud)
码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 1000; i++)
{
Items.Add("Stackoverflow"+i);
}
}
private ObservableCollection<string> items = new ObservableCollection<string>();
public ObservableCollection<string> Items
{
get { return items; }
set { items = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
