【问题标题】:Progressbar in ListBox Background?ListBox背景中的进度条?
【发布时间】:2013-06-04 04:48:12
【问题描述】:

我有以下列表框:

    <ListBox Margin="5" Grid.Column="0" Name="ListboxSelectUpdate">
        <ListBox.ItemTemplate>
            <DataTemplate>

                <ProgressBar Visibility="Visible">
                    <ProgressBar.Style>
                        <Style TargetType="{x:Type ProgressBar}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Progress}" Value="0">
                                    <Setter Property="Visibility" Value="Hidden"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ProgressBar.Style>
                    <ProgressBar.Template>
                        <ControlTemplate>
                            <AdornedElementPlaceholder Name="adorner">
                                <Grid>
                                    <TextBlock Width="70" FontStyle="Italic" FontWeight="Bold">Version:</TextBlock>
                                    <TextBlock FontWeight="Bold" Text="{Binding Path=Version}"></TextBlock>
                                </Grid>
                            </AdornedElementPlaceholder>
                        </ControlTemplate>
                    </ProgressBar.Template>
                </ProgressBar>

            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

在此列表框中,我想显示程序的不同可用更新/版本。 现在我想在 ItemTemplate 的背景中有一个 Progressbar,它只有在 Progess-Property (int) 不为零时才可见。 (所以如果更新开始,Progress-Property 不是零,Progressbar 应该是可见的)。 我的问题:我什么都看不到,没有进度条,也没有 TexbBlocks。 我的错误在哪里?

【问题讨论】:

    标签: c# wpf listbox progress-bar


    【解决方案1】:

    您的模板有点错误。您误用了AdornedElementPlaceholder 元素,根据MSDN,该元素应仅用于验证模板。而且你不要把东西放在AdornedElementPlaceholder 里面,它是一个放置装饰控件的地方。如果您想将控件堆叠在一起,请使用Grid。试试这个ListBox 模板:

    <ListBox Margin="5" ItemsSource="{Binding Path=MyList}">
      <ListBox.ItemContainerStyle>
          <Style TargetType="{x:Type ListBoxItem}">
              <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
          </Style>
      </ListBox.ItemContainerStyle>
      <ListBox.ItemTemplate>
          <DataTemplate>
              <Grid>
                  <ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress, Mode=OneWay}">
                      <ProgressBar.Style>
                          <Style TargetType="{x:Type ProgressBar}">
                              <Style.Triggers>
                                  <DataTrigger Binding="{Binding Progress}" Value="0">
                                      <Setter Property="Visibility" Value="Hidden"/>
                                  </DataTrigger>
                              </Style.Triggers>
                          </Style>
                      </ProgressBar.Style>
                  </ProgressBar>
                  <StackPanel Orientation="Horizontal">
                      <TextBlock Width="70" FontStyle="Italic" FontWeight="Bold">Version:</TextBlock>
                      <TextBlock FontWeight="Bold" Text="{Binding Path=Version}"/>
                  </StackPanel>
              </Grid>
          </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
    

    【讨论】:

      猜你喜欢
      • 2014-08-05
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-16
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多