此刻,我能想到的兩種可能的解決方案:爲你的邊界
1.計算縮放屬性綁定到
<Grid>
<Grid.Resources>
<ScaledSizeProperties x:Key="BorderSizes"
ScaleFactor="2"
BorderThickness="1"
CornerRadius="5"
Height="{Binding NewLabelTemplate.Height}"
Width="{Binding NewLabelTemplate.Width}"/>
</Grid.Resources>
...
<Border x:Name="Border"
Grid.Row="3"
Grid.ColumnSpan="2"
Background="White"
BorderBrush="Black"
VerticalAlignment="Top"
BorderThickness="{Binding
Path=ScaledBorderThickness, Source={StaticResource BorderSizes}}"
CornerRadius="{Binding
Path=ScaledCornerRadius, Source={StaticResource BorderSizes}}"
Height="{Binding
Path=ScaledHeight, Source={StaticResource BorderSizes}}"
Width="{Binding
Path=ScaledWidth, Source={StaticResource BorderSizes}}">
...
</Border>
...
</Grid>
和代碼:
public class ScaledSizeProperties : DependencyObject
{
//add input DependencyProperties for:
//double ScaleFactor
//double BorderThickness
//double CornerRadius
//double Height
//double Width
//add output DependencyProperties for:
//double ScaledBorderThickness
//double ScaledCornerRadius
//double ScaledHeight
//double ScaledWidth
public double ScaleFactor
{
get { return (double) GetValue(ScaleFactorProperty); }
set { SetValue(ScaleFactorProperty, value); }
}
public static readonly DependencyProperty ScaleFactorProperty =
DependencyProperty.Register("ScaleFactor", typeof(double),
typeof(ScaledSizeProperties),
new PropertyMetadata(1, OnScaleFactorChanged));
private static void OnScaleFactorChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
//recalculate all size properties
}
public double Height
{
get ...
set ...
}
... DependencyProperty HeightProperty ... OnHeightChanged ...
private static void OnHeightChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
//recalculate ScaledHeight
}
}
2.使用LayoutTransformer而不是RenderTransform
作爲工具包一部分的LayoutTransformer現在是SL5以來的基本庫Silverlight的官方部分。
<Grid>
...
<LayoutTransformer
Grid.Row="3"
Grid.ColumnSpan="2"
VerticalAlignment="Top">
<LayoutTransformer.LayoutTransform>
<ScaleTransform CenterX="0.5"
CenterY="0.5"
ScaleX="2"
ScaleY="2"/>
</LayoutTransformer.LayoutTransform>
<Border x:Name="Border"
Background="White"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="5"
Height="{Binding NewLabelTemplate.Height}"
Width="{Binding NewLabelTemplate.Width}">
...
</Border>
</LayoutTransformer>
...
</Grid>
一般而言,您希望父母爲孩子指定那些東西,而不是相反。爲什麼不直接將高度/寬度直接應用於ChildWindow? – 2014-10-03 13:54:13
@ChrisW。因爲邊框只是子窗口中的一個元素,我不希望縮放其他元素。 – ChrisF 2014-10-03 13:58:00
這就是爲什麼你不想使用縮放比例,縮放將與任何東西的大小進行交互,更不用說父母了。不幸的是,縮放不起作用。無論哪種方式,父母將設置該縮放將可見的位置的面板邊界。所以你不得不爲它提供空間。 – 2014-10-03 14:09:16