In my app, when you go to a mode that does destructive actions, like erasing data, certain colors turn red.
I have done this using an Observable mapping to two dictionaries.
Colors.js:
var defaultColors = {
unselected: "#3283CE",
selected: "#81C3FF"
}
var eraseColors = {
unselected: "#B75743"
selected: "#E67474"
}
module.exports = {
defaultColors: defaultColors,
eraseColors: eraseColors
};
Then I have a function in some other file that swaps the Observable’s value.
var theme = Observable(Colors.defaultColors)
function swapColors() {
if (!swap) {
theme.value = Colors.eraseColors
swap = true
} else {
theme.value = Colors.defaultColors
swap = false
}
}
I now have a bunch of radio buttons on the screen that use an Attractor to smoothly change their (un)selected color:
<Attractor ux:Name="ColorAttractor" Target="Background.Color" Value="{colors.unselected}" Type="Easing" Duration="0.1" DurationExp="0" />
This works pretty great! When the mode is changed, the Attractor reacts and the color transitions. But now, I also want it to transition between a selected color as well.
<WhileSelected>
<Change ColorAttractor.Value="{colors.selected}" />
</WhileSelected>
When the color scheme is set to the default one, and I select a radio button, it turns to {colors.selected}
.
But, when I change the color scheme to eraseColors, every single button changes it’s background back to {colors.unselected}
!
This is probably because the WhileSelected Event only triggers once and when the color scheme Observable is changed to eraseColors, the Change animator or WhileSelected Event doesn’t react again, making the Attractor’s Value change to the respective color scheme’s {colors.unselected}
.
How could I make this work?