【问题标题】:Binding on a List<UserControl>绑定列表<UserControl>
【发布时间】:2013-01-23 10:12:59
【问题描述】:

我遇到了一些绑定问题...

Shapes 是自定义用户控件的列表,例如,其中一个用户控件可以是具有某些特定属性的椭圆。我的目标是在此列表上循环并显示所有 UserControl(它可以是椭圆或矩形...)我只想显示 UserControl,就像我只是提示他的 XAML 内容一样。

这是我的网格,我只是不知道在 DataTemplate 中放什么,我尝试了一些不同的东西,但实际上没有任何效果,希望一些可以帮助我:)

<Grid>
    <s:ScatterView ItemsSource="{Binding Shapes}">
        <s:ScatterView.ItemContainerStyle>
            <Style TargetType="s:ScatterViewItem">
                <Setter Property="Background" Value="Transparent"></Setter>
            </Style>
            </s:ScatterView.ItemContainerStyle>
            <s:ScatterView.ItemTemplate>
            <DataTemplate>
                <class:Shape ShapeItem="{Binding}" />
            </DataTemplate>
        </s:ScatterView.ItemTemplate>
    </s:ScatterView>
</Grid>

【问题讨论】:

  • 如果您的 ShapeItem 是 UserControl。您是否尝试将其与ContentContentControl 属性绑定?
  • 实际上我刚刚做了: 并且效果很好......(Shape 是一个自定义的 UserControl)。感谢您的回答,我在这方面很愚蠢:(

标签: c# wpf binding user-controls pixelsense


【解决方案1】:

如评论中所述。如果您的 ShapeItem 是 UserControl,请尝试将其与内容属性绑定。

【讨论】:

    猜你喜欢
    • 2015-07-23
    • 1970-01-01
    • 2012-10-08
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2012-06-06
    相关资源
    最近更新 更多