question

EduardoGomez-1870 avatar image
0 Votes"
EduardoGomez-1870 asked HuiLiu-MSFT commented

Scrooll inside item control

Hello I have a WPF item, where I create text boxes dynamically, but I cannot do any scolling


     <Window.DataContext>
     <vm:MainWindowVM />
 </Window.DataContext>

 <WrapPanel>
     <Grid Margin="10">
         <Grid.RowDefinitions>
             <RowDefinition Height="Auto" />
             <RowDefinition Height="600" />
             <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="110" />
             <ColumnDefinition Width="200" />
         </Grid.ColumnDefinitions>

         <Label Content="Number of folders: " />

         <TextBox
             Grid.Column="1"
             VerticalAlignment="Center"
             PreviewTextInput="FolderNames_count"
             Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />

         <Button
             Grid.Column="1"
             HorizontalAlignment="Right"
             VerticalAlignment="Center"
             BorderBrush="Transparent"
             Command="{Binding CreateCommand}"
             Content="Create"
             Focusable="False" />

         <ItemsControl
             Grid.Row="1"
             Grid.ColumnSpan="2"
             ItemsSource="{Binding TextBoxesCollection}" />
         <Button Grid.Row="2" Content="Create structure" />
     </Grid>
 </WrapPanel>

</syncfusion:ChromelessWindow>


I tried to put y item template inside y Item control, but it did not wwork

dotnet-wpf-xaml
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ EduardoGomez-1870.
If you want to scroll the contents of the ItemsControl, you could add a ScrollViewer outside the ItemsControl.

  <ScrollViewer  Grid.Row="1"
              Grid.ColumnSpan="2">
             <ItemsControl Name="ic" Background="Pink"
              ItemsSource="{Binding TextBoxesCollection}" />
    </ScrollViewer>

And What do you mean I tried to put y item template inside y Item control? Have you created a template to scroll the ItemsControl? Or for other purposes?
The picture of result:
133347-7.gif


0 Votes 0 ·
7.gif (145.7 KiB)

it works, but133743-screenshot-2021-09-20-214616.png how can I make the scroll appears when there are x number of items


0 Votes 0 ·

1 Answer

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered HuiLiu-MSFT commented

If you want to scroll the items of the ItemsControl horizontally and vertically, you could add a ScrollViewer outside the ItemsControl.
When the height and width of the ScrollViewer is less than the height and width of the ItemsControl, you can scroll the ScrollViewer vertically and horizontally to view the complete items.

 <ScrollViewer  Grid.Row="1"  Width="300" Height="300" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"
              Grid.ColumnSpan="2">
             <ItemsControl Name="ic" Background="Pink"
              ItemsSource="{Binding TextBoxesCollection}" />
 </ScrollViewer>

The code to create textbox:

  public ICommand CreateNewTextBoxCommand
     {
       get => new HelperCommand((state) =>
       {
         TextBox tb = new TextBox();
         tb.Width = 400;
         Num = DateTime.Now.ToLongTimeString();
         tb.Text = Num;
         TextBoxesCollection.Add(tb);
         RaisePropertyChanged(nameof(Num));
       });
 }

The picture of the result:
133803-2.gif


If the response is helpful, please click "Accept Answer" and upvote it.
 Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


2.gif (72.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@ EduardoGomez-1870. May I know if you have a chance to check my answer? I am glad to help if you have any others questions.

0 Votes 0 ·