首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ItemsPanelTemplate中的TemplateBinding

ItemsPanelTemplate中的TemplateBinding
EN

Stack Overflow用户
提问于 2009-03-29 09:16:33
回答 1查看 2.3K关注 0票数 3

我正在用Silverlight构建一个自定义的ItemsControl,它允许项目在运行时水平或垂直显示。如何将ItemsPanel的Orientation属性绑定到父控件的Orientation属性?我试过使用TemplateBinding (它在ControlTemplate中工作),但似乎不能在ItemsPanelTemplate中工作,我是不是做错了什么?

代码语言:javascript
复制
<Style TargetType="CustomItemsControl">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="{TemplateBinding Orientation}" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-03-29 12:05:41

使用RelativeSource:

代码语言:javascript
复制
<Style TargetType="CustomItemsControl">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="{Binding Orientation, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CustomItemsControl}}}" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>

评论后编辑: Silverlight不支持RelativeSource,但Colin Eberhardt的this post解释了如何手动实现它。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/694368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档