简体   繁体   中英

Listbox Column to have a scrollviewer

In my WPF application I have a ListBox with a grid and one of the column of the grid contains names and these names could be long .Is it possible to have a scrollbar or Scroll Viewer anything limited to just Column 1 (as it has names and they could vary in width) and rest list box would have a common scrollviewer. Can it have two ScrollViewer one for entire ListBox and one dedicated to a column 1 that has names.Is it possible?

My xaml code below

<ListBox BorderThickness="0" x:Name="newListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Margin="0,2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="130" />
                     </Grid.ColumnDefinitions>
                       <TextBlock Text="{Binding Count}" 
                       HorizontalAlignment="Center"/>
                       <TextBlock Grid.Column="1" Text="{Binding 
                           FileName}" />                        
                    <ProgressBar Grid.Column="2" Minimum="0" Maximum="100" 
                   Foreground="DarkGreen" Value="{Binding Status}" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Yes this could be done ..try doing this.. I have edited your code a little

     <ListBox BorderThickness="0" x:Name="newListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid  ShowGridLines="True" Margin="0,2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="100" />
                        <ColumnDefinition Width="130" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding Count}" HorizontalAlignment="Center"/>
                    <ScrollViewer  VerticalScrollBarVisibility="Disabled" CanContentScroll="True" Grid.Column="1" HorizontalScrollBarVisibility="Visible">
                        <TextBlock Text="{Binding FileName}" />
                    </ScrollViewer>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM