Listview不显示带有自定义UserControl的滚动条

时间:2019-04-05 12:20:53

标签: c# wpf listview data-binding user-controls

downloadcontrols添加到我的ObservableCollection<DownloadControl>时 它们会显示在XAML的ListView中。但是,如果不设置显式的高度,我将无法显示滚动条。当我将滚动条设置为显示时。它出现在左侧而不是右侧,这使我相信装订位置不正确。但是无法使其正常工作。我仅使用标签和绑定使用了不同的Listview,它们的行为与预期的一样。

我尝试使用gridviewgridviewcolumn更改布局,我尝试弄乱DataTemplate,但这会导致UserControl上的数据绑定中断。 / p>

我当前在主窗口中显示的xaml在列表视图中显示自定义用户控件

<ListView Name="ListViewDownloads" ItemsSource="{Binding DownloadControls}">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="500"/>
         </GridView>
     </ListView.View>
</ListView>
public ObservableCollection<DownloadControl> DownloadControls
{
    get => (ObservableCollection<DownloadControl>)GetValue(DownloadControlsProperty);
    set => SetValue(DownloadControlsProperty, value);
}

// Using a DependencyProperty as the backing store for DownloadControls.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty DownloadControlsProperty =
   DependencyProperty.Register("DownloadControls", 
   typeof(ObservableCollection<DownloadControl>), typeof(MainWindow));

用户控件DownloadControl

<UserControl x:Class="Robeats_Desktop.UserControls.DownloadControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Robeats_Desktop.UserControls"
             mc:Ignorable="d">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250" />
            <ColumnDefinition Width="1*" MinWidth="150" />
        </Grid.ColumnDefinitions>
        <Image Source="{Binding Source}" HorizontalAlignment="Left" VerticalAlignment="Top" />
        <Grid Grid.Column="1" Name="GridInfo">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="70" />
                <ColumnDefinition Width="3*" MaxWidth="250" />
            </Grid.ColumnDefinitions>
            <StackPanel>
                <Label>Title:</Label>
                <Label>Uploader:</Label>
                <Label>Duration:</Label>
            </StackPanel>
            <StackPanel Grid.Column="1">
                <Label Content="{Binding Title}" HorizontalAlignment="Left"
                       VerticalAlignment="Top" />
                <Label Content="{Binding Uploader}" HorizontalAlignment="Left"
                       VerticalAlignment="Top" />
                <Label Content="{Binding Duration}" HorizontalAlignment="Left"
                       VerticalAlignment="Top" />
                <ProgressBar Value="{Binding Progress}" Background="Transparent" Name="ProgressBarDownload" />
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

current result  这是当前结果。预期的结果是,当我的元素大于窗口的当前高度时,在右侧具有滚动条。

完整的源代码:https://github.com/robeats-player/Robeats-Desktop

0 个答案:

没有答案