UWP - How to bind different SolidColorBrush through a Status?
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
add a comment |
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
add a comment |
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
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
xaml uwp
edited Nov 21 '18 at 4:02
asked Nov 21 '18 at 3:50
HeroWong
1218
1218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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 useForeground="{ThemeResource xxxx}"
, but value is dynamic :(
– HeroWong
Nov 21 '18 at 5:54
If i understand correctly , you want to change toSystemControlForegroundBaseLowBrush
whenif 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 6:21
Whether a UWP app hasOnThemeChanged
event?
– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 useForeground="{ThemeResource xxxx}"
, but value is dynamic :(
– HeroWong
Nov 21 '18 at 5:54
If i understand correctly , you want to change toSystemControlForegroundBaseLowBrush
whenif 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 6:21
Whether a UWP app hasOnThemeChanged
event?
– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
add a comment |
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
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 useForeground="{ThemeResource xxxx}"
, but value is dynamic :(
– HeroWong
Nov 21 '18 at 5:54
If i understand correctly , you want to change toSystemControlForegroundBaseLowBrush
whenif 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 6:21
Whether a UWP app hasOnThemeChanged
event?
– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
add a comment |
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
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
edited Nov 21 '18 at 4:56
answered Nov 21 '18 at 4:51
MKH
21729
21729
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 useForeground="{ThemeResource xxxx}"
, but value is dynamic :(
– HeroWong
Nov 21 '18 at 5:54
If i understand correctly , you want to change toSystemControlForegroundBaseLowBrush
whenif 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 6:21
Whether a UWP app hasOnThemeChanged
event?
– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
add a comment |
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 useForeground="{ThemeResource xxxx}"
, but value is dynamic :(
– HeroWong
Nov 21 '18 at 5:54
If i understand correctly , you want to change toSystemControlForegroundBaseLowBrush
whenif 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 6:21
Whether a UWP app hasOnThemeChanged
event?
– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 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 '18 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 '18 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 '18 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 '18 at 6:21
Whether a UWP app has
OnThemeChanged
event?– HeroWong
Nov 21 '18 at 6:27
Whether a UWP app has
OnThemeChanged
event?– HeroWong
Nov 21 '18 at 6:27
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
Maybe this post help you
– MKH
Nov 21 '18 at 6:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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