将XAML WPF Progressbar放入ListBox宽度自动调整窗口大小(XAML WPF Progressbar into ListBox width auto strecht with t

编程入门 行业动态 更新时间:2024-10-22 07:46:52
将XAML WPF Progressbar放入ListBox宽度自动调整窗口大小(XAML WPF Progressbar into ListBox width auto strecht with the window resize)

我正在使用进度条来表示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模板上):

的Horizo​​ntalAlignment = “弹力” Horizo​​ntalContentAlignment = “弹力”

但是具有以下相同的结果:

请注意,进度栏项目结果正确拉伸,但压缩的结果栏(灰色和格林可见部分)(见红色箭头)。

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

本文发布于:2023-07-22 10:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   放入   大小   窗口   ListBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!