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