XAML HorizontalAlignment=”Stretch” works in editor but not in program

I’m setting up the UI (WPF) for an app and I am having a weird problem with a list view. Each “item” in the list view is a small block, which I would like to be resizable with the window changing size. When editing, and I have commented out the <ListBox> and associated tags, the block appears correctly (note, there will be text in the top line).

However, when I add <ListBox> and it’s associated tags (so can no longer see it in the editor), and run the app, the blocks all resize to “minimum width”. Note that when highlighting tags in the editor, <ListBox> and <ListBox.ItemTemplate> show the full frame as per the image above, but <DataTemplate> onwards shows no highlights (as expected).

If I fiddle with the exact order of of the elements, I occasionally (and I do mean occasionally, after fiddling for ages) get it to appear correctly, but then when I change anything, anywhere in the XAML, it breaks again.

When even getting it working just in the editor, I did find it very susceptible to the order of the elements, so I suspect something at work there, but I’m out of ideas.

Below is the relevant XAML, with the three associated <ListBox> tags commented out. Any ideas out there about why it’s not rendering properly? Or why it “magically” works only occasionally? Or how to “debug” how/why/when it’s getting changed from Horizonal Alignement = "Stretch" to "something else"?

Thanks in advance.

        <Grid Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,0,0,25">
<!--
            <ListBox x:Name="ListIt"  HorizontalAlignment="Stretch"  BorderThickness="0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
-->
                        <Grid x:Name="FileComp" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,5,5,5" >
                            <Frame BorderBrush="Black" BorderThickness="1,1,1,1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0" Height="40" />
                            <Label x:Name="FFN" Margin="-3,-3,0,-3" HorizontalAlignment="Left" Content="{Binding FullFileName }" />
                            <ProgressBar x:Name="ProgBar" HorizontalAlignment="Stretch" Height="15" Margin="3,0,99,3" VerticalAlignment="Bottom" 
                                         Minimum="{Binding ActivityBar.Minimum }" Maximum="{Binding ActivityBar.Maximum }" Value="{Binding ActivityBar.Value }" />
                            <TextBox x:Name="F1Act" Text="1" BorderBrush="Black" BorderThickness="1,1,1,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,19,80,3" Height="15" Width="15" 
                                   Background="{Binding FileActivity[0].Background }" Visibility="{Binding FileActivity[0].Visibility}" FontSize="9" FontWeight="Bold" Foreground="Black" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Focusable="False" IsTabStop="False" AllowDrop="False" IsHitTestVisible="False" />
                            <TextBox x:Name="F2Act" Text="2" BorderBrush="Black" BorderThickness="1,1,1,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,19,61,3" Height="15" Width="15" 
                                   Background="{Binding FileActivity[1].Background }" Visibility="{Binding FileActivity[1].Visibility}" FontSize="9" FontWeight="Bold" Foreground="Black" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Focusable="False" IsTabStop="False" AllowDrop="False" IsHitTestVisible="False" />
                            <TextBox x:Name="F3Act" Text="3" BorderBrush="Black" BorderThickness="1,1,1,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,19,42,3" Height="15" Width="15" 
                                   Background="{Binding FileActivity[2].Background }" Visibility="{Binding FileActivity[2].Visibility}" FontSize="9" FontWeight="Bold" Foreground="Black" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Focusable="False" IsTabStop="False" AllowDrop="False" IsHitTestVisible="False" />
                            <TextBox x:Name="F4Act" Text="4" BorderBrush="Black" BorderThickness="1,1,1,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,19,23,3" Height="15" Width="15" 
                                   Background="{Binding FileActivity[3].Background }" Visibility="{Binding FileActivity[3].Visibility}" FontSize="9" FontWeight="Bold" Foreground="Black" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Focusable="False" IsTabStop="False" AllowDrop="False" IsHitTestVisible="False" />
                            <TextBox x:Name="F5Act" Text="5" BorderBrush="Black" BorderThickness="1,1,1,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,19,04,3" Height="15" Width="15" 
                                   Background="{Binding FileActivity[4].Background }" Visibility="{Binding FileActivity[4].Visibility}" FontSize="9" FontWeight="Bold" Foreground="Black" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Focusable="False" IsTabStop="False" AllowDrop="False" IsHitTestVisible="False" />
                        </Grid>
            <!--
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
-->
        </Grid>

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật