简体   繁体   中英

XAML WPF Progressbar into ListBox width auto strecht with the window resize

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>

在此处输入图片说明

在此处输入图片说明

I tried also with (on the ProgressBar template):

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

but with the same following result:

在此处输入图片说明

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

ListBox上设置HorizontalContentAlignment="Stretch"应该可以。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM