Wpf 以XAML为单位保持栅格星形大小不变

Wpf 以XAML为单位保持栅格星形大小不变,wpf,visual-studio-2010,xaml,resources,Wpf,Visual Studio 2010,Xaml,Resources,我想在XAML中的其他地方定义4/3比率,然后使用它。大概是这样的: <Grid.RowDefinitions> <RowDefinition Height="4*"/> <RowDefinition Height="3*"/> </Grid.RowDefinitions> 4 3. 当然,这个代码是不正确的,不能产生预期的效果。如何正确执行此操作?行定义的类型是,因此您需要在资源中创建GridLength实例: <Sys

我想在XAML中的其他地方定义4/3比率,然后使用它。大概是这样的:

<Grid.RowDefinitions>
    <RowDefinition Height="4*"/>
    <RowDefinition Height="3*"/>
</Grid.RowDefinitions>
4
3.
当然,这个代码是不正确的,不能产生预期的效果。如何正确执行此操作?

行定义的类型是,因此您需要在资源中创建
GridLength
实例:

<System:Double x:Key="Top_Part">4</System:Double>
<System:Double x:Key="Bottom_Part">3</System:Double>

<Grid.RowDefinitions>
    <RowDefinition Height="{StaticResource Top_Part}"/>
    <RowDefinition Height="{StaticResource Bottom_Part}"/>
</Grid.RowDefinitions>

4*
3*
行定义的类型是,因此您需要在资源中创建
GridLength
实例:

<System:Double x:Key="Top_Part">4</System:Double>
<System:Double x:Key="Bottom_Part">3</System:Double>

<Grid.RowDefinitions>
    <RowDefinition Height="{StaticResource Top_Part}"/>
    <RowDefinition Height="{StaticResource Bottom_Part}"/>
</Grid.RowDefinitions>

4*
3*