Canvasを含むDataTemplateでListBoxを使用しています。次に、そのキャンバスを含むグリッドの左/上をバインドして、特定のポイントに移動します。
次に、指定したX、Y座標を中心に子グリッドを配置します。子グリッドのサイズは、その内容に基づいて変化します。私は、TranslateTransformを使用してグリッドをその幅の半分だけ移動することによってこれを達成することを計画していました。
そのTranslateTransformを設定する方法がわかりませんが、ElementNameバインディングがDataTemplate内で機能しないためです。これをどのように達成できるかについてのアイデアはありますか?
<ItemsControl ItemsSource="{TemplateBinding SomeCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<Grid x:Name="Container"
Canvas.Left="{Binding X}"
Canvas.Top="{Binding Y}"
Background="#88000000">
<Grid.RenderTransform>
<TranslateTransform X="{Binding ActualWidth, ElementName=Container, Converter={StaticResource NegativeHalfConverter}}"
Y="{Binding ActualHeight, ElementName=Container, Converter={StaticResource NegativeHalfConverter}}" />
</Grid.RenderTransform>
<TextBlock Text="{Binding SomeValue}" FontSize="36" Foreground="White" />
</Grid>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
`