【发布时间】:2015-06-09 06:28:55
【问题描述】:
我有一个 WP 8.1 应用程序。我正在遵循完整的 MVVM 设计模式。在 XAML 代码中
<Grid>
<Canvas x:Name="gameCanvas"
Width="{Binding CanvasWidth,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
<ItemsControl ItemsSource="{Binding Path=ButtonItems,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate x:Name="Dta">
<Button x:Name="newsItemBtn"
Height="{Binding Height}"
Width="{Binding Width}"
Style="{StaticResource ButtonStyle2}"
Content="{Binding Content}"
Command="{Binding
Path=DataContext.ButtonClickCommand,
ElementName=gameCanvas}"
CommandParameter="{Binding Content}">
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
但我想要的是在运行时动态分配按钮的样式。
我在GamePage.XAML. 中定义了三个按钮样式
<Style x:Key="ButtonStyle1" />
<Style x:Key="ButtonStyle2" />
<Style x:Key="ButtonStyle3" />
现在基于ViewModel 上的某些值或某些属性,我想选择按钮样式
我尝试使用converter。但没有太大的成功。
知道如何实现这一目标吗?
【问题讨论】:
标签: c# .net xaml mvvm windows-phone-8.1