代码之家  ›  专栏  ›  技术社区  ›  atsjoo

在ItemsControl数据模板中设置画布属性

  •  69
  • atsjoo  · 技术社区  · 17 年前

    我正在尝试数据绑定到这个 ItemsControl :

    <ItemsControl ItemsSource="{Binding Path=Nodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
    

    DataTemplate ,我正在尝试单独定位我的 Node 网络上的元素 Canvas

    <DataTemplate DataType="{x:Type Model:EndNode}">
        <Controls:EndNodeControl Canvas.Left="{Binding Path=XPos}" Canvas.Top="{Binding Path=YPos}" />
    </DataTemplate>
    

    1 回复  |  直到 6 年前
        1
  •  143
  •   Dany Haddad Arcturus    6 年前

    Canvas . ItemsControl 将放置 ContentPresenter

    <ItemsControl ItemsSource="{Binding Path=Nodes}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="Canvas.Left" Value="{Binding Path=XPos}" />
                <Setter Property="Canvas.Top" Value="{Binding Path=YPos}" />
            </Style>
        </ItemsControl.ItemContainerStyle>
    </ItemsControl>
    
    推荐文章