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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:10:30+00:00 2026-05-16T20:10:30+00:00

I have a frustrating problem that I would much appreciate some help with. I

  • 0

I have a frustrating problem that I would much appreciate some help with. I have a ListView within a ViewBox and I can’t get the items within the ListView to stretch horizontally.

Here is the XAML:

<Window x:Class="WpfApplication3.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication3"
        Title="Window1">
    <Window.Resources>
        <local:Inning x:Key="inning">
            <local:Inning.Skins>
                <local:Skin SkinNumber="1"></local:Skin>
                <local:Skin SkinNumber="2"></local:Skin>
                <local:Skin SkinNumber="3"></local:Skin>
            </local:Inning.Skins>
        </local:Inning>
    </Window.Resources>
    <Grid DataContext="{StaticResource inning}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBlock Background="Black"
                   Text="SKINS"
                   Foreground="White"
                   FontSize="80"
                   FontWeight="Bold"
                   HorizontalAlignment="Center"></TextBlock>
        <Grid Margin="2"
              Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Viewbox>
                <ListView Name="lvSkinNumbers"
                          ItemsSource="{Binding Skins}"
                          HorizontalAlignment="Stretch"
                          Background="Black"
                          VerticalAlignment="Stretch"
                          VerticalContentAlignment="Stretch">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock FontSize="250"
                                       VerticalAlignment="Stretch"
                                       LineStackingStrategy="BlockLineHeight"
                                       Margin="2"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Stretch"
                                       Background="Black"
                                       Foreground="White"
                                       Text="{Binding SkinNumber}"></TextBlock>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Viewbox>
            <Viewbox Grid.Column="1">
                <ListView Name="lvFirstInningSkins"
                          ItemsSource="{Binding Skins}"
                          Grid.Column="1"
                          HorizontalContentAlignment="Stretch"
                          Background="Black">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock FontSize="250"
                                       VerticalAlignment="Stretch"
                                       LineStackingStrategy="BlockLineHeight"
                                       Margin="2"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Stretch"
                                       Background="Green"
                                       Foreground="White"
                                       Text="{Binding SkinNumber}"></TextBlock>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Viewbox>
            <Viewbox Grid.Column="2"
                     HorizontalAlignment="Stretch">
                <ListView Name="lvSecondInningSkins"
                          ItemsSource="{Binding Skins}"
                          Grid.Column="2"
                          HorizontalAlignment="Stretch"
                          Background="Black">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock FontSize="250"
                                       VerticalAlignment="Stretch"
                                       LineStackingStrategy="BlockLineHeight"
                                       Margin="2"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Stretch"
                                       Background="Green"
                                       Foreground="White"
                                       Text="{Binding SkinNumber}"></TextBlock>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Viewbox>
        </Grid>
    </Grid>
</Window>

Here is the code behind with the definitions of the Skin and Inning objects:

using System;
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WpfApplication3
{

 public class Inning
 {
  private ObservableCollection<Skin> _skins = new ObservableCollection<Skin>();
  public ObservableCollection<Skin> Skins
  {
   get { return _skins; }
   set { _skins = value; }
  }
 }

 public class Skin : INotifyPropertyChanged
 {
  public Skin()
  {
  }

  public Skin( int skinNumber, Inning inning )
  {
   this.SkinNumber = skinNumber;
   this.Inning = inning;
  }

  public Inning Inning { get; set; }
  public int SkinNumber { get; set; }

  public int SkinCount
  {
   get { return this.Inning.Skins.Count; }
  }

  public void Notify( string propertyName )
  {
   if ( PropertyChanged != null )
    PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) );
  }

  public event PropertyChangedEventHandler PropertyChanged;

 }


 public partial class Window1 : Window
 {

  public Window1()
  {
   InitializeComponent();
  }


 }
}

The number of skins that can occur in an inning can change, and can be changed by the user, so I’ve put the ListViews into ViewBoxes so they automatically resize accordingly when the number of skins change. The resulting window can be seen here: http://i52.tinypic.com/244wqpl.jpg

I’ve tried all sorts of combinations of HorzontalAlignment="Stretch" and HorizontalContentAlignment="Stretch" and tried modifying the ItemsPanel template but I can’t for the life of me seem to figure out how to get the ListView to stretch horizontally. Is what I’m trying to do impossible without some code behind to alter the width of the ListView dynamically? Or am I missing something really simple?

Any help that anyone can offer would be most appreciated.

Thanks,

Matthew

  • 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-16T20:10:30+00:00Added an answer on May 16, 2026 at 8:10 pm

    Try setting the ItemContainerStyle for your ListView to something like:

    <ListView>
      <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
      </ListView.ItemContainerStyle>
    </ListView>
    

    You also might need to set <Viewbox Stretch="Fill"/>.

    After this, I think you can remove all those other “HorizontalAlignment = Stretch” and “HorizontalContentAlignment = Stretch” setters in your code since it probably won’t be necessary anymore.

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

Sidebar

Related Questions

No related questions found

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.