【问题标题】:Putting a scoll bar on a wrap panel contained within an items control将滚动条放在项目控件中包含的包装面板上
【发布时间】:2009-05-22 12:04:27
【问题描述】:

有人知道如何将滚动条添加到包含在 itemscontrol 中的包装面板中吗?

【问题讨论】:

    标签: .net wpf scrollbar itemscontrol wrappanel


    【解决方案1】:

    这里不行,

        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <ScrollViewer>
                    <WrapPanel Orientation="Horizontal"  />
                </ScrollViewer>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    

    你得到一个讨厌的例外, ItemsPanelTemplate 的 VisualTree 必须包含一个 Panel。 'System.Windows.Controls.ScrollViewer' 不是面板。

    【讨论】:

      【解决方案2】:

      在它周围包裹一个 ScrollViewer 标记

      <ScrollViewer>
         <WrapPanel>
            <!-- your other controls here -->
         </WrapPanel>
      </ScrollViewer>
      

      【讨论】:

        【解决方案3】:

        这个示例(从 Kaxaml 示例修改)应该可以帮助您:

            <Page
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
           <Grid>
            <Grid.Resources>
               <XmlDataProvider x:Key="flickrdata" Source="http://api.flickr.com/services/feeds/photos_public.gne?tags=flower&amp;lang=en-us&amp;format=rss_200">
                  <XmlDataProvider.XmlNamespaceManager>
                     <XmlNamespaceMappingCollection>
                        <XmlNamespaceMapping Prefix="media" Uri="http://search.yahoo.com/mrss/"/>
                     </XmlNamespaceMappingCollection>
                  </XmlDataProvider.XmlNamespaceManager>
               </XmlDataProvider>
               <DataTemplate x:Key="itemTemplate">
                  <Image Width="75" Height="75" Source="{Binding Mode=OneWay, XPath=media:thumbnail/@url}"/>
               </DataTemplate>
               <ControlTemplate x:Key="controlTemplate" TargetType="{x:Type ItemsControl}">
                  <WrapPanel IsItemsHost="True" Orientation="Horizontal"/>
               </ControlTemplate>
            </Grid.Resources>
            <ScrollViewer Width="320" Height="225">
              <ItemsControl
                 Width="300"
                 ItemsSource="{Binding Mode=Default, Source={StaticResource flickrdata}, XPath=/rss/channel/item}"
                 ItemTemplate="{StaticResource itemTemplate}"
                 Template="{StaticResource controlTemplate}">
              </ItemsControl>
            </ScrollViewer>
         </Grid>
        </Page>
        

        【讨论】:

          猜你喜欢
          • 2023-03-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多