Auto size stackpanel to parent height with List views inside with scrollview

i'm a newbie in wpf and i'm trying to create two expanders that contains listview on each expander, in the header i created a searchtext box and works ok. The problem is that i cant create scrollview to the two expanders and fit the stackpanel height to the parent control. How can i create scrollview to the list views without the textbox?

Code:

<StackPanel Orientation="Vertical"> <TextBox Margin="3,3,3,3" FontSize="16" Height="25" Name="searchTextBox" TextChanged="SearchTextBox_OnTextChanged" Grid.Row="0"></TextBox> <Border CornerRadius="6" BorderBrush="Gray" BorderThickness="1" DockPanel.Dock="Top" Grid.Row="1"> <StackPanel Orientation="Vertical"> <Expander IsExpanded="True" Background="LightGray" Grid.Row="0" > <Expander.Header> <TextBlock Text="A" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" /> </Expander.Header> <Expander.Content> <ListView Name="RecentEngines" BorderThickness="0" > <ListView.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" FontWeight="Bold" /> </DataTemplate> </ListView.ItemTemplate> </ListView> </Expander.Content> </Expander> <Expander IsExpanded="True" Background="LightGray" Grid.Row="1"> <Expander.Header> <TextBlock Text="B" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" /> </Expander.Header> <Expander.Content> <ListView Name="Engines" BorderThickness="0" MaxHeight="300"> <ListView.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" FontWeight="Bold" /> </DataTemplate> </ListView.ItemTemplate> </ListView> </Expander.Content> </Expander> </StackPanel> </Border> </StackPanel>

--------------Solutions-------------

Per comments on the question this is probably a little easier done with Grids rather than StackPanels.

<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Name="searchTextBox"
Grid.Row="0"
Height="25"
Margin="3,3,3,3"
FontSize="16" />
<Border Grid.Row="1"
BorderBrush="Gray"
BorderThickness="1"
CornerRadius="6">
<ScrollViewer Height="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Expander Grid.Row="0"
Background="LightGray"
IsExpanded="True">
<Expander.Header>
<TextBlock VerticalAlignment="Bottom"
FontSize="22"
FontWeight="Bold"
Foreground="Gray"
Text="A" />
</Expander.Header>
<Expander.Content>
<ListView Name="RecentEngines" BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Expander.Content>
</Expander>

<Expander Grid.Row="1"
Background="LightGray"
IsExpanded="True">
<Expander.Header>
<TextBlock VerticalAlignment="Bottom"
FontSize="22"
FontWeight="Bold"
Foreground="Gray"
Text="B" />
</Expander.Header>
<Expander.Content>
<ListView Name="Engines"
MaxHeight="300"
BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

</Expander.Content>
</Expander>

</Grid>
</ScrollViewer>
</Border>
</Grid>

There were also a few redundant markup elements I've pulled. You want to try and avoid that as much as possible as it can play havoc with deeply nested elements. The 'Grid.Row' element here is redundant as it's inside a StackPanel:

<Expander IsExpanded="True" Background="LightGray" Grid.Row="0" >

Category:wpf Time:2017-12-05 Views:1

Related post

  • how auto size the columns width of a list view in virtual mode? 2012-02-13

    When I use a TListView (ViewStyle = vsReport) I can autofit the width of the columns setting the LVSCW_AUTOSIZE or LVSCW_AUTOSIZE_USEHEADER values in the Width property of each column, now I start to use the Listview in virtual mode, but the width of

  • how can we set Height of list view in java file? 2011-08-22

    Hi I am fetching data for List View from web and want to set Height of List View according to data no of elements in List View are not fix, so I am trying below code but its gives error at run time, so any one can help me to solve this problem, thank

  • Fragment with list view is not replacing the list when it should? 2011-10-05

    I'm fairly new to Android development so I'm sorry if I haven't given all the information you need. Basically I'm building a basic file browser but I wanted to try something different out by having a list view of all the files in a fragment. Here's w

  • Table view with list view 2011-09-07

    i need to use table view with list view.. 1st column is fixed and can be scrolled vertically only and columns after that are vertically and horizontally scrollable The functionality will be like table view is horizontally scrollable and on vertical s

  • Lazy load with List View Titanium 2013-11-06

    Am using 3.1.3.GA sdk, Alloys and 2.3.4 Android Emulator. With List View, I created items to show and there are around 300 items I have to show in List View. As per TableView we can use scroll event for lazy load, but List View doesnt support scroll

  • How to create a table with fixed length inside a scrollView in Appcelerator Titanium? 2011-11-17

    I'm trying to add some imageViews and a tableView into scrollView in Titanium. I want the scrollView to be scrollable but not the tableView inside, so I set tableView.scrollable to false. However, even if the height of the scrollView exceeds the heig

  • Scrolling issues with a ListView inside a ScrollView 2010-10-24

    Here's the scenario conceptually (excluding linearlayouts) ScrollView Button Checkboxes Spinner ListView (full-size, non-scrolling) AdMob advert i.e. a scrolling pane, which has a filtering UI at the top, followed by results, but the advert must alwa

  • Android list view inside tab focus issue 2011-11-19

    I have a TabHost with a ListView inside a tab. When the activity starts, I can't scroll the list view until I have clicked off the tab that the activity starts on, and then re-select the tab with the list view inside it. Note, I can get the list view

  • 2 Floating divs, Need the first one to auto-size according to parent div and 2nd floating div 2011-04-13

    This is how my code may go:- <div id="parent" style="width:49%"> <div id="left" style="float:left;clear:both;width:auto">BLAH!BLAH!Content goes here</div> <div id="right" style="float:left;clear:both:width:250px">Content again

  • MVC3 passing parent entity in list view 2011-02-08

    I am fairly new to MVC3. I am trying to achieve the following: Page with list of sections: @model IEnumerable<Demo.Models.Section> I iterate through the sections and display some info. Within each section there is a list of items. Those items a

  • two tabs, one with list view, the other with expandable list view. a couple problems 2011-05-02

    So I have two tabs. One has a custom list view which is working fine. The other has an expandable list view which has two problems. So first problem is that when the activity is started, the lists from the two tabs are overlapped. When I switch tabs,

  • Strange Behavior of in List View click with Section Header 2011-06-18

    I am having a Custom List view with Section Header.Custom List is as follows : Note : This is not ordinary list. Its Section Header Before clicking the like image it looks like Image 1 and after click it should changed like Image 2. My problem is tha

  • Weird behavior of spinner in TablelLayout with list view 2012-01-19

    I am trying to put table layout in list view in that table layout i have one spinner which is not displaying properly it is stretched in width and doesn't looks good. I am inflating the table layout in the getView() method of CustomAdapter which exte

  • Creating personal list view programmatically with "Manage personal views" permissions only 2011-01-21

    In project, I'm currently working on, I have to create personal list view for given list (SharePoint 2007). Here is my code (currList is SPList): System.Collections.Specialized.StringCollection viewFields = currList.Views[BaseViewID].ViewFields.ToStr

  • How to create list view with another view inside it? 2011-04-26

    I want to make some similiar view like this one. title bar with info about "money" or "point" upside, list of upgrades in the middle, and button (not necessary) below. I'm able to create the listview by code, but I don't know how to put those title b

  • I have problem with List View in Android? 2011-05-19

    I have list view which contains 2 buttons and 2 textviews. I change the text of button on Click event. but when I scroll the listview the text of button is changed. How to overcome this problem? example. [text1][text2][button hide][button2]---> th

  • Dialog with list view and message 2011-06-21

    I need to create dialog with both ListView and message, however according to http://code.google.com/p/android/issues/detail?id=10948 it is not possible with standard AlertDialog. So I've decided to create custom view with text and listview, and attac

  • problem with list view in android using arraylist items 2011-06-22

    in my app i am using a list view. The data which i want to list out are from a database of my app and an xml server database. For example i am getting some two set of data from server and store it in a array as follows firstname = {arun, Arun, Rajesh

  • How to get parent of Tree(List)View Item? 2011-07-14

    i'm currently working on a project which shall display some date in a hierarchical way. I'm using a Tree(List)View (the one from Ricciolo) which has 3 hierarchical levels. The ItemsSource of the TLV is a List. 1st level = typeof(Game) 2nd level = typ

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 1.904 (s). 13 q(s)