3

I am new to wpf and i need help. i must show n vertical elements(stackpanels) horizontally. I used a horizontal stackpanel to put all n vertical stackpanels in it and i put horizontal stackpanel in a scrollviewer. this is the xaml code below:

`<Window x:Class="Results.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
    <telerik:RadButton x:Name="radButton" Content="Button" HorizontalAlignment="Left" Height="Auto" Margin="407,66,0,0" VerticalAlignment="Top" Width="Auto" Click="radButton_Click"/>
    <Grid>
        <ScrollViewer  Height="96" Margin="10,115,0,0"  Width="497" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
            <StackPanel x:Name="teststack" HorizontalAlignment="Left" Height="94" VerticalAlignment="Top" Width="497" Orientation="Horizontal"/>
        </ScrollViewer>
    </Grid>
</Grid>`

This is c# code for generating n elements below(where col in vertical and teststack is horizontal):

for (int i = 0; i < arrowcount; i++)
{
    StackPanel col = new StackPanel();
    TextBox row = new TextBox();
    Image img = new Image();
    col.Children.Add(row);
    col.Children.Add(img);
    teststack.Children.Add(col);
}

this image is my unwanted result.because I put 20 elements to show but there is 12 elements to see without scrollbar. my ideal is a horizontal scrollbar be visible in this image under elements. please suggest me an edit if I asked my problem in wrong way.

0

1 Answer 1

3

Try without Height and Width of ScrollViewer.

<ScrollViewer  Margin="10,115,0,0" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
     <StackPanel x:Name="teststack" HorizontalAlignment="Left" Height="94" VerticalAlignment="Top" Width="497" Orientation="Horizontal"/>
</ScrollViewer>
Sign up to request clarification or add additional context in comments.

1 Comment

@siamakwork: Is it working without height and width?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.