Panel.IsItemsHost到底做什么? [英] What exactly does Panel.IsItemsHost do?

查看:295
本文介绍了Panel.IsItemsHost到底做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Panel.IstItemsHost附加属性有什么用途?

What does the Panel.IstItemsHost attached property used for?

我看到很多人在ItemsControl的ItemsContainer模板上设置它的示例,但是MSDN上的未文档说明不能解释设置属性赋予的原因或好处.

I see plenty of examples of people setting it on the ItemsContainer template for an ItemsControl, but the un-documentation over at MSDN does not explain why or what advantages setting property confers.

推荐答案

说我有一个ItemsControl.我想使用一个自定义面板,当您滚动时,它可以向内和向外翻转项目;它称为SwoopPanel.现在,如何告诉ItemsControl使用我的SwoopPanel包含它创建的模板?

Say I have an ItemsControl. I want to use a custom panel that swoops items in and out as you scroll; its called a SwoopPanel. Now, how do I tell the ItemsControl to use my SwoopPanel to contain the templates it creates?

快速方法是在ItemsControl上设置ItemsPanel:

The quick way is to set the ItemsPanel on the ItemsControl:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <lol:SwoopPanel />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

但是,有时候这对您不起作用.也许您希望自定义SwoopPanel在UI中的显示方式,解决此问题的唯一方法是更改​​ItemsControl的控件模板.现在,您可以将SwoopPanel直接添加到控件模板,并使用该属性将其标记为ItemsHost,ItemsControl将放置它创建的所有模板化项目.

However, sometimes that doesn't work for you. Maybe you wish to customize how the SwoopPanel is presented in the UI, and the only way to get around this is to change the control template of the ItemsControl. Now you can add your SwoopPanel directly to the control template and, using the property, mark it as the ItemsHost that the ItemsControl will put all the templated items it creates.

<Style TargetType="ItemsControl">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ItemsControl">
        <Border CornerRadius="5">
          <ScrollViewer VerticalScrollBarVisibility="Hidden">
            <lol:SwoopPanel IsItemsHost="True"/>
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

您是否必须以一种或另一种方式来做?不.一个比另一个更有利吗?好吧,第二种方法可以让您更多地控制UI,第一种方法更容易.随您选择吧,真的.我从来没有亲自用第二种方法做过,但是我认为可能在几个地方可能有用.

Do you have to do it one way or the other? No. Is one more advantageous than the other? Well, the second way allows you more control of the UI, the first way is easier. Take your pick, really. I've never personally done it the second way, but I think there might be a couple of places where it might be useful.

这篇关于Panel.IsItemsHost到底做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆