2

我有一个ItemsControl模板化为 UserControl 的项目。我ItemsControl.Items Panel的模板是Canvas.


现在,我手动设置了这些我的用户控件的宽度和高度属性,它看起来像这样:

<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>



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

4

1 回答 1

0

您是否尝试过相对源绑定?

例如

Width="{Binding ActualWidth,
                RelativeSource={RelativeSource AncestorType=Canvas}}"
于 2012-07-23T04:41:15.543 回答