在ItemsControl项目上显示滚动条

时间:2014-06-17 12:09:37

标签: c# wpf

ItemsControl中的每个项目 - 这里是TextBox - 如何显示垂直滚动条?

我不希望所有扩展器周围都有垂直滚动条。

这就是我尝试过的代码:

<ItemsControl ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding Path=ErrorLogs}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>                       
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Expander Margin="0"  Header="{Binding FileName}" Background="Green">
                <Controls:BindableTextBox Background="Red"                                         
                    Text="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </Expander>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

1 个答案:

答案 0 :(得分:0)

您有两个选择

1,在scrollviewer中包装

<DataTemplate>
    <Expander Margin="0"
              Header="{Binding FileName}"
              Background="Green">
        <ScrollViewer VerticalScrollBarVisibility="Visible">
            <Controls:BindableTextBox Background="Red"
                                      Text="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </ScrollViewer>
    </Expander>
</DataTemplate>

2,在文本框上启用多行

例如

<DataTemplate>
    <Expander Margin="0"
              Header="{Binding FileName}"
              Background="Green">
        <TextBox Background="Red"
                 AcceptsReturn="True" TextWrapping="Wrap"
                 Text="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
    </Expander>
</DataTemplate>

我不确定Controls:BindableTextBox所以使用多行取决于可用性