由DataTemplate填充的ListBox不会滚动WPF

时间:2012-07-16 10:29:20

标签: c# wpf xml listbox scroll

我通过以下代码填写列表框:

<ListBox Height="188" HorizontalAlignment="Left" Margin="277,0,0,0" Name="listBoxAtributeValue" VerticalAlignment="Top" Width="191" MaxHeight="188" MaxWidth="191">
        <ItemsControl ItemsSource="{Binding Path=.}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Black" Offset="0" />
                                <GradientStop Color="#FFFFA029" Offset="1" />
                            </LinearGradientBrush>
                        </StackPanel.Background>
                            <Label Content="{Binding lblText}" />
                            <TextBox Text="{Binding txtBoxContent}" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ListBox>

但我无法滚动它。 这是listBox的图像:Here

我该如何解决?亲爱的。

1 个答案:

答案 0 :(得分:1)

您的ItemsControl内不需要ListBoxListBox已经是ItemsControl