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 8446801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:01:03+00:00 2026-06-10T10:01:03+00:00

I have an ListBox UserControl and there is a grid control in the DataTemplate.

  • 0

I have an ListBox UserControl and there is a grid control in the DataTemplate. I used the MVVM to bind the data. For Orientation change, I am able to change the wide of the ListBox, but I don’t find the solution to change the grid column width inside the listbox. Would you help me how to do it or provide a example or link to me. Thanks in advance.

There is my UserControl.xaml

<UserControl x:Class="CMSPhoneApp.QueueListControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"
xmlns:local="clr-namespace:CMSPhoneApp"  >

<UserControl.Resources>       
    <local:VisibilityConverter x:Key="VisibilityConverter"/>
    <local:ColumSpanConverter x:Key="ColumSpanConverter"/>        
</UserControl.Resources>

    <ListBox x:Name="lst" HorizontalAlignment="Left"  Margin="6,6,0,0"  VerticalAlignment="Top" Width="400"    
                  ItemsSource="{Binding Path=MyQueue}"   
                      SelectedItem="{Binding Path=CurrentQueue, Mode=TwoWay}" Height="380" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border BorderThickness="1,1,1,1" BorderBrush="Blue">
                            <Grid x:Name="grd" Width="auto" HorizontalAlignment="Stretch"  >                                  
                                    <Grid.RowDefinitions>                                          
                                    <RowDefinition Height="auto"/>
                                </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="35" />
                                        <ColumnDefinition Width="250"/>
                                        <ColumnDefinition Width="125" />
                                    </Grid.ColumnDefinitions>
                                    <Image Source="{Binding Type}" Grid.Row="0" Grid.Column="0"/>
                                    <TextBlock  Grid.Row="0" Grid.Column="1"  Grid.ColumnSpan= "{Binding isSpan, Converter={StaticResource ColumSpanConverter}}" Text="{Binding summary}" TextWrapping="Wrap"
                                             Style="{StaticResource PhoneTextAccentStyle}"  />
                                    <Button x:Name="btnAction" Grid.Row="0" Grid.Column="3" ClickMode="Press" Click="btnAction_Click" Style="{StaticResource ButtonStyle1}"
                                            Visibility="{Binding isVisibility, Converter={StaticResource VisibilityConverter}}"
                                         Tag="{Binding callNumber}">

                                        <Button.Content>
                                            <TextBlock Width="85" Height="70" Text="{Binding ActionCaption}" 
                                                       Style="{StaticResource LabelStyle_20}"     />
                                        </Button.Content>
                                    </Button>

                                </Grid>
                                </Border>
                    </DataTemplate>                    

                </ListBox.ItemTemplate>
            </ListBox>

The OrientationChange code:

 private void TestPage_OrientationChanged(
object sender, OrientationChangedEventArgs e)
    {
        ListBox lstControl = lst.lst;           
        Grid g = lstControl.ItemContainerGenerator.ContainerFromIndex(0) as Grid;   


        if (e.Orientation.ToString().Contains("Portrait"))                
             lst.lst.Height = 400;


        else                        
        lst.lst.Height = 120;
    }
  • 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-06-10T10:01:04+00:00Added an answer on June 10, 2026 at 10:01 am

    Instead of absolute values for the column width, you should use percentage or “Star Sizing”. Star sizing allows the width of a column (or height of a row) to grow or shrink as the available size changes.

    Here is an example to use:

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width=".1*" />
        <ColumnDefinition Width=".6*"/>
        <ColumnDefinition Width=".3*" />
    </Grid.ColumnDefinitions>
    

    Along with this you should remove the Width value of the ListBox and allow it to fill all available space.

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

Sidebar

Related Questions

I have a usercontrol that I want to use as a ListBoxItem. <ListBox.ItemTemplate> <DataTemplate>
Is there a way to pop a usercontrol/control let say a Grid,ViewBox or custom
I have added a DataTemplate to a ListBox class to bind my collection to:
Within my project I have a Listbox which uses a datatemplate. Within this data
I have several winforms listbox controls I am hosting in a user control. The
I have a custom user control extending the Listbox class. Inside of it I
I have a silverlight listbox that is being used as a search result box.
In WPF, I have a ListBox with a UserControl as its ItemTemplate - all
I have a listbox that uses a UserControl as the item template. Inside the
I have a listbox in my silverlight usercontrol and I am filling it with

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.