Path Position Incorrect When Using Bindings To Populate Paths Data Attribute

前端 未结 1 1647
醉酒成梦
醉酒成梦 2021-01-25 21:31

I have a hard coded Path shape inside of a Canvas. I want to have multiple shapes inside this canvas so I\'m trying to shove the information of each s

相关标签:
1条回答
  • 2021-01-25 22:07

    The Canvas.Left and Canvas.Top bindings in your ItemTemplate have no effect, because the Path control in the DataTemplate does not have a Canvas parent.

    In order to make it work you would have to set the ItemsPanel and ItemContainerStyle properties like this:

    <ItemsControl ItemsSource="{Binding CanvasPaths}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemContainerStyle>
            <Style TargetType="ContentPresenter">
                <Setter Property="Canvas.Left" Value="{Binding CanvasLeft}"/>
                <Setter Property="Canvas.Top" Value="{Binding CanvasTop}"/>
            </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Path Style="{StaticResource OverlayPath}" 
                      Data="{Binding Data}" 
                      Height="{Binding Height}" 
                      Width="{Binding Width}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    0 讨论(0)
提交回复
热议问题