我正在使用进度条来表示WPF应用程序中传输的数据。
一个新的进度条(和一个进入ListBox的新项目)将被动态实例化为每次传输。
我有一个XAML GUI问题:progres栏的大小是固定的,并且不随窗口的宽度延伸。 窗口的每个元素在窗口大小调整时都会正确反应,除了宽度仍然固定的progres栏外。
我怎样才能让我的进度条宽度自动适应ListBox?
以下是相对于ListBox和进度条模板的XAML代码部分:
<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>
我也试过(在ProgressBar模板上):
的HorizontalAlignment = “弹力” HorizontalContentAlignment = “弹力”但是具有以下相同的结果:
请注意,进度栏项目结果正确拉伸,但压缩的结果栏(灰色和格林可见部分)(见红色箭头)。
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"应该可以工作。
Setting HorizontalContentAlignment="Stretch" on the ListBox should work.
更多推荐
ListBox,progress,进度,电脑培训,计算机培训,IT培训"/> <meta name="descripti
发布评论