我正在构建这个 xaml 树:
<ContentPresenter x:Name="CardContentPresenter"
Height="{Binding ActualWidth,
ElementName=CardContentPresenter,
Converter={StaticResource WidthToHeightConverter},
Mode=OneWay}"
VerticalAlignment="Center">
<Border x:Name="CardBorder">
<Border x:Name="ContentBorder"
Width="{Binding ActualWidth,
ElementName=CardBorder,
Converter={StaticResource WidthToContentWidthConverter},
Mode=OneWay}"
Height="{Binding ActualHeight,
ElementName=CardBorder,
Converter={StaticResource WidthToContentWidthConverter},
Mode=OneWay}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid>
<ContentPresenter x:Name="CardContentContentPresenter"
Height="{Binding ActualWidth,
ElementName=CardContentContentPresenter,
Converter={StaticResource HeightToWidthConverter},
Mode=OneWay}"
VerticalAlignment="Center">
<Grid />
</ContentPresenter>
</Grid>
</Border>
</Border>
</ContentPresenter>
但正如我通过转换器内部的断点看到的那样,高度/宽度的计算顺序很混乱(例如,内部内部高度在内部宽度之前计算,因此该值不正确)。
如何控制属性计算的顺序?或者我的整个方法都是错误的,还有另一种方法来处理它?