首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绑定ItemsTemplate数据模板和ItemsPanelTemplate属性

绑定ItemsTemplate数据模板和ItemsPanelTemplate属性
EN

Stack Overflow用户
提问于 2012-06-28 20:19:20
回答 1查看 360关注 0票数 2

我有一个以UserControl为模板的ItemsControl。我的ItemsControl.Items Panel被模板化为Canvas

现在,我手动设置了我的用户控件的width和height属性,结果如下所示:

代码语言:javascript
复制
<ItemsControl x:Name="curveList"
              ItemsSource="{Binding SplineVMList}"
              Background="{x:Null}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas x:Name="canvas" Margin="46,60,83,46"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <local:SplineControl Width="300" Height="300" Canvas.Bottom="0" Canvas.Left="0" IsSelected="{Binding IsSelected, Mode=TwoWay}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Bottom" Value="0"/>
            <Setter Property="Canvas.Left" Value="0"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

我想要的是将我的用户控件的宽度和高度属性绑定到画布的宽度和高度属性。这是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2012-07-23 12:41:16

你有没有尝试过相对的源代码绑定?

例如:

代码语言:javascript
复制
Width="{Binding ActualWidth,
                RelativeSource={RelativeSource AncestorType=Canvas}}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11244504

复制
相关文章

相似问题

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