2

我有一個ItemsControl模板作爲UserControl的項目。 我的ItemsControl.ItemsPanel被模板化爲Canvas綁定ItemsTemplate數據模板和ItemsPanelTemplate屬性


現在,我手動設置這些我的用戶的width和height屬性,它看起來像這樣:

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



我想是綁定width和height屬性我的用戶控件對我的畫布。 只是可能嗎?

回答

0

您是否嘗試過使用相對源綁定?

例如

Width="{Binding ActualWidth, 
       RelativeSource={RelativeSource AncestorType=Canvas}}" 
相關問題