开发者

Silverlight Scrollviewer, making children fill all of the space

I've got a scroll viewer within a grid view and the scroll viewer takes up a percentage of the screen.

Within the scroll viewer I have a listbox, which I add items to in code.

The problem is that I can't get the listbox to take up all of the space available within the parent scrollviewer.

Just wondering if this is even possible.

Thanks,

Matt

EDIT:

<Grid x:Name="LayoutRoot" Background="White" Margin="0,8,0,0"     Loaded="LayoutRoot_Loaded">
    <Grid.RowDefinitions>
        <RowDefinition Height="0.06*"/>
        <RowDefinition Height="0.06*" />
        <RowDefinition Height="0.88*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.155*"/>
        <ColumnDefinition Width="0.845*"/>
    </Grid.ColumnDefinitions>
  ...
   <ListBox x:Name="lstReportTypes" BorderBrush="Black" Margin="0" BorderThickness="0" Foreground="#FF737FE0" FontSize="10.667" Background="{x:Null}" SelectionChanged="lstReportTypes_SelectionChanged" Grid.Row="2" G开发者_Python百科rid.Column="1">
    <ListBoxItem Content="Item 1" Foreground="#FF737FE0" Background="Transparent" Cursor="Hand"/>
    <ListBoxItem Content="Item 2" Foreground="#FF737FE0" Background="Transparent" Cursor="Hand"/>
    <ListBoxItem Content="item 3dafasdfasdfasdfsdfasdfasdfasdf" Foreground="#FF737FE0" Background="Transparent" Cursor="Hand"/>
   </ListBox>

The code above is a small snippet of the code, the listbox appears in the correct position and with the correct width. The items do not seem to take all of the parents width though, they all clip. If I select one of the items the selected outline is the correct width however.

Hope this extra information helps


You don't need a ScrollViewer if you intend to have only a ListBox inside, taking the whole space. A ListBox already displays scroll bars when its content exceeds the available space.

You can separately control which scrollbar appears with ScrollViewer.HorizontalScrollBarVisibility="Hidden".

If you have more elements in you ScrollViewer please give more details.

EDIT:
The XAML you provided gave me this result (with a pink backgound to show the listbox boundaries):

Silverlight Scrollviewer, making children fill all of the space

The whole listbox is scrolled and the items are clipped. Isn't that the desired effect? If you want each listbox item to scroll separately you need to specify a custom ItemTemplate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜