0
votes

I am using a progress bar to represents the transferred data in a WPF application.

A new progress bar (and a new item into the ListBox) will be instantiated dynamically a for each transfer.

I have a XAML GUI problem: the size of the progres bar is fixed and doesn't stretch with the width of the window. Each elements of the windows reacts correctly at window resize except for the progres bar which width still remains fixed.

How I can made my progress bar width automatically fitted into the ListBox?

Here is the portion of XAML code relative to the ListBox and the progress bar template:

    <ListBox Grid.Column="2" Name="TransfersList" Margin="0.111,0,-0.222,34.889" ItemsSource="{Binding DataTx}"
             SelectionChanged="TransfersList_SelectionChanged" Grid.Row="1" Grid.ColumnSpan="2">
        <ListBox.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Ottieni informazioni" Click="GetInfo" />
                <MenuItem Header="Metti in pausa" Click="PauseTransfer" />
                <MenuItem Header="Riprendi trasferimento" Click="ResumeTransfer" />
                <MenuItem Header="Annulla trasferimento" Click="StopTransfer" />
            </ContextMenu>
        </ListBox.ContextMenu>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <ProgressBar Height="20" Minimum="0" Maximum="100" Name="gasparino_il_carbonaro"
                             Value="{Binding PbStatus}" Width="177" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

enter image description here

enter image description here

I tried also with (on the ProgressBar template):

  • HorizontalAlignment="Stretch"
  • HorizontalContentAlignment="Stretch"

but with the same following result:

enter image description here

Note that the progress bar item results correctly stretched, but the bar (grey and gree visible part) results compressed (see red arrow).

1
Did you try using HorizontalAlignment="Stretch" on the ProgressBar?José Pedro
Yes, I tried with HorizontalContentAlignment but not working.shogitai
HorizontalContentAlignmentaybe
Both HorizontalContentAlignment and HorizontalContentAlignment give the same weird result.shogitai
Did you set HorizontalContentAlignment="Stretch" on the ListBox?José Pedro

1 Answers

2
votes

Setting HorizontalContentAlignment="Stretch" on the ListBox should work.