2
public DateTime? ToDate { get; set; }

status is ToDate, I added a property to model. logic looks like:

public SolidColorBrush ToDateForeground
{
    get
    {
        if (ToDate.HasValue && ToDate.Value <= DateTime.Now)
        {
            return new SolidColorBrush(Colors.Red);
        }
        return Application.Current.Resources["SystemControlForegroundBaseLowBrush"];
    }
}

Xaml

<TextBlock Foreground="{x:Bind ToDateForeground, Mode=OneWay}" Text="Test" />

It can work, however, if the user changes the Windows color to Dark, the ToDateForeground doesn't automatically change.

How to deal with it, just like ThemeReource?

HeroWong
  • 499
  • 1
  • 5
  • 14
  • I found a better solution. [github](https://github.com/Microsoft/fluent-xaml-theme-editor/issues/13) – HeroWong Apr 23 '19 at 02:19

1 Answers1

1

Did you tried to handle Windows color changes for your App:

                    var uiSettings = new UISettings();
                    var color = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);

                    if (color == Windows.UI.Colors.Black) // Dark Mode
                    {
                        this.RequestedTheme = ApplicationTheme.Dark;
                    }
                    else if (color == Windows.UI.Colors.White) //Light Mode
                    {
                        this.RequestedTheme = ApplicationTheme.Light;
                    }

if the user changes the Windows color to Dark, the ToDateForeground doesn't automatically change.

Change RequestedTheme for your app then all theme resources will changes to match current theme colors. please take a look at ApplicationTheme

MKH
  • 367
  • 1
  • 4
  • 12
  • No need to switch app theme, the theme of the app should follow the system. `x:Bind` won't follow changes of system. therefore, I must use `Foreground="{ThemeResource xxxx}"`, but value is dynamic :( – HeroWong Nov 21 '18 at 05:54
  • If i understand correctly , you want to change to `SystemControlForegroundBaseLowBrush` when `if statement` return **false** so its doesn't change (when user choose new Color Mode for Windows) because it already set. So you need to update app theme to update ThemeResource color values base on App theme. – MKH Nov 21 '18 at 06:21
  • Whether a UWP app has `OnThemeChanged` event? – HeroWong Nov 21 '18 at 06:27
  • Maybe this [post](https://stackoverflow.com/q/43437703/5541998) help you – MKH Nov 21 '18 at 06:46
  • To get ThemeChanged event, you can try [Theme Listener](https://learn.microsoft.com/en-us/windows/communitytoolkit/helpers/themelistener) – Ritesh Patel Feb 26 '19 at 16:35