UWP - How to bind different SolidColorBrush through a Status?











up vote
1
down vote

favorite












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?










share|improve this question




























    up vote
    1
    down vote

    favorite












    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?










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      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?










      share|improve this question















      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?







      xaml uwp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 4:02

























      asked Nov 21 at 3:50









      HeroWong

      1068




      1068
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          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






          share|improve this answer























          • 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 at 5: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 at 6:21












          • Whether a UWP app has OnThemeChanged event?
            – HeroWong
            Nov 21 at 6:27










          • Maybe this post help you
            – MKH
            Nov 21 at 6:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405009%2fuwp-how-to-bind-different-solidcolorbrush-through-a-status%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          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






          share|improve this answer























          • 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 at 5: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 at 6:21












          • Whether a UWP app has OnThemeChanged event?
            – HeroWong
            Nov 21 at 6:27










          • Maybe this post help you
            – MKH
            Nov 21 at 6:46















          up vote
          0
          down vote













          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






          share|improve this answer























          • 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 at 5: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 at 6:21












          • Whether a UWP app has OnThemeChanged event?
            – HeroWong
            Nov 21 at 6:27










          • Maybe this post help you
            – MKH
            Nov 21 at 6:46













          up vote
          0
          down vote










          up vote
          0
          down vote









          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






          share|improve this answer














          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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 4:56

























          answered Nov 21 at 4:51









          MKH

          538




          538












          • 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 at 5: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 at 6:21












          • Whether a UWP app has OnThemeChanged event?
            – HeroWong
            Nov 21 at 6:27










          • Maybe this post help you
            – MKH
            Nov 21 at 6:46


















          • 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 at 5: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 at 6:21












          • Whether a UWP app has OnThemeChanged event?
            – HeroWong
            Nov 21 at 6:27










          • Maybe this post help you
            – MKH
            Nov 21 at 6:46
















          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 at 5:54




          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 at 5: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 at 6:21






          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 at 6:21














          Whether a UWP app has OnThemeChanged event?
          – HeroWong
          Nov 21 at 6:27




          Whether a UWP app has OnThemeChanged event?
          – HeroWong
          Nov 21 at 6:27












          Maybe this post help you
          – MKH
          Nov 21 at 6:46




          Maybe this post help you
          – MKH
          Nov 21 at 6:46


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405009%2fuwp-how-to-bind-different-solidcolorbrush-through-a-status%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berounka

          Sphinx de Gizeh

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...