Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6378583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:38+00:00 2026-05-25T02:01:38+00:00

<Border CornerRadius=2,2,2,2 BorderThickness=1 BorderBrush=LightSkyBlue Margin=5,2,2,2 x:Name=PersonBorder Visibility=Collapsed> <StackPanel Orientation=Vertical> <ListBox Name=personListBoxTest BorderThickness=0 ScrollViewer.HorizontalScrollBarVisibility=Hidden ScrollViewer.VerticalScrollBarVisibility=Auto

  • 0
    <Border CornerRadius="2,2,2,2" BorderThickness="1" BorderBrush="LightSkyBlue" Margin="5,2,2,2" x:Name="PersonBorder" Visibility="Collapsed">
            <StackPanel Orientation="Vertical">

 <ListBox Name="personListBoxTest" 
          BorderThickness="0"
          ScrollViewer.HorizontalScrollBarVisibility="Hidden"
          ScrollViewer.VerticalScrollBarVisibility="Auto"
          HorizontalContentAlignment="Stretch"
          Background="LemonChiffon"
          >
    <ListBox.ItemTemplate >
        <DataTemplate>
            <StackPanel>
                <StackPanel Orientation="Horizontal" Background="Pink">
                    <StackPanel Orientation="Horizontal" Visibility="{Binding ElementName=Involvement, Path=Text, Converter={StaticResource cIsVisibleOrCollapsed}}" Margin="0,0,5,0">
                        <TextBlock Text="Involvement:"/>
                        <TextBlock Margin="5,0,0,0" Text="{Binding Path=NameInvolvementType}" Foreground="Blue" x:Name="Involvement"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock  Text="Name:"/>
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=FirstName}" Foreground="Blue" />
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=MiddleName}" Foreground="Blue" />
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=LastName}" Foreground="Blue" />
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=NameSuffix}" Foreground="Blue" />
                        <TextBlock Margin="5,0,0,0" Text="DOB:"/>
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=BirthDate, StringFormat=MM/dd/yyyy}" Foreground="Blue" />
                    </StackPanel>
                </StackPanel>
                <StackPanel  Visibility="{Binding ElementName=myEventAddress,Path=Visibility, Converter={StaticResource cVisibilityMirror}}" Orientation="Horizontal" >
                    <TextBlock Text="Address:" />
                    <EventDet:EventAddress Margin="5,0,0,0" x:Name="myEventAddress" Foreground="Blue" CityTextBlockOrientation="Horizontal" />
                </StackPanel>

                <StackPanel Visibility="{Binding ElementName=Phone1, Path=Text, Converter={StaticResource cIsVisibleOrCollapsed}}" Orientation="Horizontal">
                    <TextBlock Text="Home:" />
                    <TextBlock Margin="5,0,0,0" Text="{Binding Path=Phone1}" Foreground="Blue" x:Name="Phone1"/>
                </StackPanel>
                <StackPanel Visibility="{Binding ElementName=Phone2, Path=Text, Converter={StaticResource cIsVisibleOrCollapsed}}" Orientation="Horizontal">
                    <TextBlock Text="Mobile:" />
                    <TextBlock Margin="5,0,0,0" Text="{Binding Path=Phone2}" Foreground="Blue" x:Name="Phone2"/>
                </StackPanel>
                <StackPanel Visibility="{Binding ElementName=Phone3, Path=Text, Converter={StaticResource cIsVisibleOrCollapsed}}" Orientation="Horizontal">
                    <TextBlock Text="Work:" />
                    <TextBlock Margin="5,0,0,0" Text="{Binding Path=Phone3}" Foreground="Blue" x:Name="Phone3"/>
                </StackPanel>


                <StackPanel x:Name="PersonAlertSP" Visibility="Collapsed" Background="WhiteSmoke">
                    <TextBlock Text="Alerts:" />
                    <ListBox ItemsSource="{Binding Path=PersonAlertList}" x:Name="PersonAlertListBox"  BorderThickness="1" >
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=AlertType}" Margin="0,0,5,0" Foreground="Blue" Width="150"/>
                                    <TextBlock Text="{Binding Path=Description}" Margin="0,0,5,0" Foreground="Blue"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>


            </StackPanel>

        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

</StackPanel>
</Border>

code behind:

//this is a little unweidly, but its test code until this works
MobileWPF.singleton.EventDetailsTabControl.myEventDetailControl.personListBoxTest.ItemsSource =
    dc.SessionEvent.SessionPersons.ToList();

Here’s an image of the result with 6 items, all the data is nonsense test data:

screenshot

EDIT 2:

After playing around with it a bit, I guess this is what’s happening… First the ListBox is greedy and takes the maximum amount of vertical space, then some IValueConverter computations are done, and some elements are collapsed. However, once this is done, the ListBox height is not being updated.

EDIT 3:

I tried converting PersonListBoxTest into an ItemsControl, instead of a ListBox, with teh only difference in code being that and the <ItemsControl.ItemTemplate > declaration… And now it works as expected, no extra whitespace.

So somehow the ItemsControl respects the fact that some of my elements are collapsed through the IValueConverters, and the ListBox doesn’t. I played around with the VirtualizingStackPanel attribute in ListBox, setting IsVirtualizing to both true and false (no change), before testing the ItemsControl.

I’ll give the points to anyone who can explain why it works how I observed it.
Thanks for your answers everyone, you never know what’s going to make the difference.

Here’s an example of an IValueConverter, which is being used, they are all about the same.

[ValueConversion(typeof(object), typeof(System.Windows.Visibility))]
public class NullToVisibleOrCollapsed : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null) return System.Windows.Visibility.Collapsed;

        if (value is Image)
        {
            if (((Image)value).Source == null) return System.Windows.Visibility.Collapsed;
            return System.Windows.Visibility.Visible;
        }

        if (value is string)
        {
            string myString = (string)value;
            if (string.IsNullOrEmpty(myString) == true)
                return System.Windows.Visibility.Collapsed;
        }

        if (value is int)
        {
            int myInt = (int)value;
            if (myInt == 0)
                return System.Windows.Visibility.Collapsed;
        }

        return System.Windows.Visibility.Visible;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:01:38+00:00Added an answer on May 25, 2026 at 2:01 am

    The reason this is happening is because ListBox overrides the default ItemsPanelTemplate settings to use a VirtualizingStackPanel. It does this because VirtualizingStackPanel supports UI virtualization, meaning that only the visible controls are evaluated and created, which can improve performance over large sets of data.

    During UI virtualization, a control checks the visibility of a child element, then measures it and its descendants. This order of evaluation is the key reason you are seeing extra space. You are using the bound value of a child element to set your parent element’s Visibility.

    <StackPanel 
        ...
        Visibility="{Binding 
                        ElementName=Phone1,
                        Path=Text,
                        Converter={StaticResource cIsVisibleOrCollapsed}}">
        <TextBlock
            x:Name="Phone1"
            Text="{Binding Path=Phone1}" />
    </StackPanel>
    

    When the framework evaluates your StackPanel, Visibility is not yet set, so it defaults to Visible. You can fix this if you changed the Visibility binding to use the same binding path as the child property instead.

    <StackPanel 
        ...
        Visibility="{Binding Phone1, 
                        Converter={StaticResource cIsVisibleOrCollapsed}}">
        <TextBlock
            x:Name="Phone1"
            Text="{Binding Path=Phone1}" />
    </StackPanel>
    

    You could also specify a FallbackValue of Collapsed, which tells the engine to use Visibility.Collapsed in the event it cannot resolve the binding. However, I’d be cautious about doing that because it seems like this would screw up the UI measurements, which might have other unwanted effects.

    Finally, the normal ItemsControl template doesn’t need to pre-measure because it doesn’t support UI virtualization. In other words, the controls are generated and then hidden and the size is adjusted accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a border defined like so: <Border x:Name=BaseBar BorderThickness=1,1,1,2 Height=29 CornerRadius=0,0,16,16 Grid.Row=2> <Border.BorderBrush>
I have the following code in silverlight for windows phone : <Border CornerRadius=0 x:Name=brdTest
I have to transition the CornerRadius property of a Border from value 0,0,0,0 to
Curve the border of silverlight listbox control: I just want to curve the ends
I changed the ControrTemplate of a button, gave it a border with CornerRadius and
I want to style my ListBox and display a Border around it. I want
I have a Border with CornerRadius property set to 10. Inside that Border ,
I have a border element with rounded corners containing a 3x3 grid. The corners
I have a border layout whose center panel is defined like the below. {
I tried : .bb { border-bottom:1px; } <tr class=bb> But no effect at all.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.