Specify width/height as resource in WPF

后端 未结 1 1807
轮回少年
轮回少年 2020-12-16 09:48

Is there a way in WPF to specify a width/height as a resource, so that it can be reused in several styles for e.g. margin/padding?

相关标签:
1条回答
  • 2020-12-16 10:19

    Sure.

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Page.Resources>
        <sys:Double x:Key="Height">200</sys:Double>
        <sys:Double x:Key="Width">200</sys:Double>
      </Page.Resources>
      <Grid>  
        <Rectangle 
          Height="{StaticResource Height}" 
          Width="{StaticResource Width}" 
          Fill="Blue"/>
      </Grid>
    </Page>
    
    0 讨论(0)
提交回复
热议问题