我试图让我的画布大小成为我在App.xaml.cs
文件中定义如下的静态属性类的特定宽度/高度:
public class CanvasAttr
{
public static double Width
{
get
{
return Window.Current.Bounds.Width / 4;
}
}
public static double Height
{
get
{
return Window.Current.Bounds.Height / 4;
}
}
}
这是我的MainPage.xaml
<Page
x:Class="Bossanova.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Bossanova"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Height="765.015">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.Resources>
<Style x:Key="DrawSurface" TargetType="Canvas">
<Setter Property="Width" Value="{Binding CanvasAttr.Width}" />
<Setter Property="Height" Value="{Binding CanvasAttr.Height}" />
<Setter Property="Background" Value="AliceBlue" />
</Style>
</Grid.Resources>
<Canvas x:Name="Main" Style="{StaticResource DrawSurface}">
</Canvas>
</Grid>
</Page>
如您所见,在<Style>
定义中,我<Setter>
为画布的 Width 和 Height 属性添加了标签。问题是一个简单的{Binding CanvasAttr.Width}
似乎不会影响任何事情。我需要做什么才能做到这一点?