在 WPF 中指定宽度/高度作为资源 [英] Specify width/height as resource in WPF

查看:72
本文介绍了在 WPF 中指定宽度/高度作为资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF 中是否有一种方法可以将宽度/高度指定为资源,以便它可以在多种样式中重用,例如边距/填充?

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?

推荐答案

好的.

<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>

这篇关于在 WPF 中指定宽度/高度作为资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆