我编写了一个示例来查看是否可以Style
在空白的 Windows 应用商店应用程序中使用绑定 - 它已编译但并没有完全按照我希望的那样工作。我对 XAML 和绑定比较陌生,所以可能错过了一些东西。
在下面的示例中,有两个矩形,都绑定到滑块控件,并且都应该在滑块移动的同时发生变化,但似乎只有第一个发生变化;第一个直接绑定,第二个通过 a 绑定style
。
在 Win Store 应用程序中绑定Style
应该是可能的吗?(我的目标是有一个滑块可以一次更改大量元素的设置,这似乎是比复制/粘贴绑定到所有元素更好的方法)
<Grid Background="#FF87873D">
<StackPanel>
<StackPanel.Resources>
<Style x:Key="myTestRectangleStyle" TargetType="Rectangle">
<Setter Property="Fill" Value="DarkBlue" />
<Setter Property="Margin" Value="10,10" />
<Setter Property="Height" Value="30" />
<Setter Property="Width" Value="{Binding ElementName=slider1, Path=Value}" />
</Style>
</StackPanel.Resources>
<Rectangle Width="{Binding ElementName=slider1, Path=Value}" Fill="Black" Margin="10,10" Height="30"/>
<Rectangle Style="{StaticResource myTestRectangleStyle}"/>
<Slider Name="slider1" Minimum="20" Maximum="200" Margin="20,0"/>
</StackPanel>
</Grid>