Specificare larghezza / altezza come risorsa in WPF
-
21-09-2019 - |
Domanda
C'è un modo in WPF per specificare una larghezza / altezza come una risorsa, in modo che possa essere riutilizzato in diversi stili per esempio margine / padding?
Soluzione
Certo.
<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow