创建动态样式并绑定到UI MVVM

时间:2019-04-24 08:59:40

标签: c# xaml uwp

我几个月来正在UWP中开发一个应用程序。我在为UI组件创建样式方面遇到困难。到目前为止,我正在进行API调用,在其中我得到带有颜色列表的json响应(下面的代码)。然后我在BaseViewModel中有一个Theme对象,该对象在api调用完成后设置。我还使用数据绑定将主题对象绑定到xaml,以便可以显示颜色。 根据我读到的一篇文章,我在App.xaml中创建了样式,如UWP - Dynamically load different Styles.xaml所述。这就是我要解决的问题,我想根据在ThemeModel(下面的代码)中收到的数据创建这些样式。

 <TextBlock
 x:Name="Count"
  FontSize="10"
 Foreground="{x:BindViewModel.Theme.DefaultColor,Converter={StaticResource   HexStringToSolidBrushConverter}, Mode=OneWay}"         
  Text="{x:Bind SymbolCount ,Mode=TwoWay}"
  HorizontalAlignment="Center"
  VerticalAlignment="Center"/>

任何建议将不胜感激。

 public class ThemeModel
 {
    public string DefaultColor { get; set; } 

    public string DefaultActionColor { get; set; }

    public string DefaultTextColor { get; set; } 

    public string DefaultTextDarkColor { get; set; }

    public string DefaultTextLightColor { get; set; }

    public string PrimaryColor { get; set; }

    public string PrimaryDarkestColor { get; set; }

    public string PrimaryDarkerColor { get; set; }

    public string PrimaryLighterColor { get; set; }

    public string PrimaryLightestColor { get; set; } 

    public string PrimaryActionColor { get; set; } 

    public string PrimaryTextColor { get; set; }

    public string PrimaryTextLightColor { get; set; }

    public string SecondaryColor { get; set; } 

    public string SecondaryDarkestColor { get; set; } 

    public string SecondaryDarkerColor { get; set; }

    public string SecondaryLightestColor { get; set; }

    public string SecondaryLighterColor { get; set; }

    public string SecondaryActionColor { get; set; }

    public string SecondaryTextColor { get; set; }

    public string SecondaryTextLightColor { get; set; }

    public string HueRedColor { get; set; }

    public string HueRedTextColor { get; set; }


}

0 个答案:

没有答案