我希望根据if else条件绑定按钮的样式。我在ViewModel中创建了一个字符串属性,并将其绑定到按钮的style属性上,例如:
<Button x:Name="copd" Content="COPD"
Command="{Binding COPDReadingsCommand}"
Style="{DynamicResource ResourceKey={Binding CheckCopd}}"
HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="20" FontWeight="Bold" />
我正在循环遍历资源字典并获取所有的键。使用if else,我在其中更改字符串属性值(CheckCopd)。
我在if else中得到了所需的值,但当我执行应用程序时,样式没有应用到按钮上。它只显示通用按钮样式。
如何绑定DynamicResource?
请给予建议?
谢谢。