我有一个以UserControl为模板的ItemsControl。我的ItemsControl.Items Panel被模板化为Canvas。
现在,我手动设置了我的用户控件的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>我想要的是将我的用户控件的宽度和高度属性绑定到画布的宽度和高度属性。这是可能的吗?
发布于 2012-07-23 12:41:16
你有没有尝试过相对的源代码绑定?
例如:
Width="{Binding ActualWidth,
RelativeSource={RelativeSource AncestorType=Canvas}}"https://stackoverflow.com/questions/11244504
复制相似问题