我需要在Canvas的左边缘和底部边缘具有TextBlock标签。沿着图线思考,但是“标签”不是指比例或标签,而是对象的其他属性,它们可能落在x,y交点处。
问题在于,标签的长度不是全部相同(但是,它们都通过转换器被截断了一定长度,所以理论上我可以计算出最长的标签吗?)所以标签“装订线”,如果您将不会在任何一个轴上知道宽度。
我曾尝试将“ XGutterCanvas”,“ ObjectCanvas”和“ YGutterCanvas”放置在自己的网格容器中,希望网格可能会强制某种形式的报告宽度,但这是行不通的,并且对象画布是不管怎样,都很难离开。我还尝试了一个具有两行没有列的网格,并将装订线和画布放在堆栈面板中,以达到相同的效果。
在现实生活中,这是一个MVVM自定义控件,每个画布具有单独的绑定的ItemsControls和DataTemplates,并且直到运行时才知道对象及其标签-这只是模拟出来的XAML来整理布局
<Border>
<Grid x:Name="Container">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid x:Name="YGutterContainer" Grid.Row="0" Grid.Column="0" Background="#FFC5C5C5">
<Canvas x:Name="YGutterCanvas">
<TextBlock Text="These" Canvas.Top="0"/>
<TextBlock Text="Labels" Canvas.Top="75"/>
<TextBlock Text="Will Not" Canvas.Top="115"/>
<TextBlock Text="Be The" Canvas.Top="250"/>
<TextBlock Text="Length" Canvas.Top="300"/>
</Canvas>
</Grid>
<Grid x:Name="ObjectCanvasContainer" Grid.Row="0" Grid.Column="1">
<Border BorderBrush="Black" BorderThickness="1">
<Canvas x:Name="ObjectCanvas" Background="#FFBDFFF9">
<Rectangle Width="30" Height="60" Canvas.Left="0" Canvas.Top="0" Fill="Transparent" Stroke="Green" />
<Rectangle Width="30" Height="30" Canvas.Left="150" Canvas.Top="75" Fill="Yellow" />
<Ellipse Width="170" Height="150" Canvas.Left="300" Canvas.Top="115" Fill="Red" />
</Canvas>
</Border>
</Grid>
<Grid x:Name="NoMansLand_AKA_Filler" Grid.Row="1" Grid.Column="0"><!--No Content Here--></Grid>
<Grid x:Name="XGutterContainer" Grid.Row="1" Grid.Column="1" Background="#FFC5C5C5">
<Canvas x:Name="XGutterCanvas">
<TextBlock Text="Detail 1a" Canvas.Left="0">
<TextBlock.RenderTransform>
<RotateTransform Angle="-45" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="Detail 2a" Canvas.Left="150">
<TextBlock.RenderTransform>
<RotateTransform Angle="-45" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="Detail 3a" Canvas.Left="300">
<TextBlock.RenderTransform>
<RotateTransform Angle="-45" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="Detail 4a" Canvas.Left="450">
<TextBlock.RenderTransform>
<RotateTransform Angle="-45" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="Detail 5a" Canvas.Left="500">
<TextBlock.RenderTransform>
<RotateTransform Angle="-45" />
</TextBlock.RenderTransform>
</TextBlock>
</Canvas>
</Grid>
</Grid>
</Border>