-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding ColorPicker.Color TwoWay to a DependencyProperty causes StackOverflowException #237
Comments
Thank you for bringing this to our attention @MattG-Seattle. @jwmsft can you help with this? |
Not only this, but another problem that might be related: When using a |
I should note that the documentation does state that |
@MattG-Seattle Thanks for the info! but how should we act in a scenario like the one I propose? I mean, using the ColorPicker control with MVVM and a Converter. I'm not sure if you have read this issue: Please, take a look. |
@SuperJMN I tried your scenario and got the same behavior. I have to believe there is an issue in the layer that translates from COM objects to .NET objects. I guess what I would do is bind |
I'm completely convinced now that there is a bug in the translation layer. I tried this: public Color SelectedColor
{
get { return ColorFromText(SelectedColorAsText); }
set
{
String newColorAsText;
newColorAsText = TextFromColor(value);
if (newColorAsText != SelectedColorAsText)
{
SelectedColorAsText = newColorAsText;
OnPropertyChanged(nameof(SelectedColor));
}
}
}
public String SelectedColorAsText { get; set; }
private Color ColorFromText(String text)
{
Byte a, r, g, b;
a = Byte.Parse(text.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
r = Byte.Parse(text.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
g = Byte.Parse(text.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
b = Byte.Parse(text.Substring(7, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
return Color.FromArgb(a, r, g, b);
}
private String TextFromColor(Color color)
{
return color.ToString();
} In my XAML for the Color="{Binding Path=SelectedColor, Mode=TwoWay}" I chose "#AARRGGBB" as my 'internal' representation. This code completely hides that internal representation from Windows, yet when Windows calls my 'get' implementation -- where I clearly return a
But most indicative of all, if I change my XAML to use |
OK, @MattG-Seattle :) Thanks for the workaround. Anyways, I hope this is fixed soon, because not everybody will be happy to include references to a Windows.UI.Color in a ViewModel! It's not strange for ViewModels to sit inside .NET Standard libraries that cannot reference anything in the UWP. Moreover, classic bindings and converters are 1st class citizen yet :P |
Please open this product issue to https://github.com/Microsoft/microsoft-ui-xaml/issues. |
A
DependencyProperty
of typeColor
incorrectly reports that its value has changed, even if the new value being set is aColor
with exactly the sameA
,R
,G
andB
values.As a result, if in a
ColorPicker
you setColor="{x:Bind Path=MyBoundColor, Mode=TwoWay}"
, whereMyBoundColor
is the CLR accessor for aDependencyProperty
of typeColor
, you will get aStackOverflowException
, as the binding continually bounces back and forth between the two DPs.For example, if you set
MyBoundColor = Colors.Red
, this change will propagate to theColorPicker
'sColor
property, which will then attempt to ensure thatMyBoundColor
is 'in sync' by settings its value toColors.Red
. However, as mentioned, that DP perceives theSetValue
toColors.Red
to be a 'change', even though it's not. So the binding setsColorPicker.Color
toColors.Red
, which again tries to synchronizeMyBoundColor
-- and so on and so forth.I think this is likely to be a common scenario in a
Page
orContentDialog
-- it's really quite a similar scenario to bindingListView.SelectedItem
to some 'backing' property or DP.The text was updated successfully, but these errors were encountered: