-
Notifications
You must be signed in to change notification settings - Fork 80
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
Custom types with defined implicit cast to bool are unsupported by BoolToVisibility converter #53
Comments
…it cast to bool are unsupported by BoolToVisibility converter Alex141#53
Hi,
If we remove cast to bool after dynamic cast, we handle implicit operators. If we leave bool cast, we can handle both explicit and implicit operators. What do you say? |
Hi Alex, your solution looks nice and beautiful, much better than my, but, unfortunately, it doesn't work for case specified.
|
Hi Roman, Ok, I compared yours and my examples. The difference is only in access modifier of CastableToBoolean. I use 'public class' and you use 'private class'. Because of privacy of the class dlr can't acess to implicit operator. Changing access modifier on 'public' solves this problem. Hmm, because the sample class models the class being used as the type of the source property, it must be public, as well as the property itself, otherwise the binding will simply not work, this is a general requirement for all properties (https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/binding-sources-overview#other-characteristics). So the solution of this problem is in changing the access modifier of convertable class to public. |
I was wondered and checked - yes, you are right. It looks a bit confusing, that access modifier is so important here, but it really works as it should. |
Ok, I glad that we solved this problem by our efforts :) I will commit the changes and release a new version tomorrow |
Version 2.3.0.1 with this fix has been released |
I faced in issue in my project. When using a type which has defined implicit cast to bool in a property, binding visibility to that property doesn't work and conversion fails with following message:
System.InvalidCastException: Specified cast is not valid.
It happens because of explicit cast is called on value in BoolToVisibilityConverter.Convert:
if ((bool)value) return Visibility.Visible;
this test reproduces issue:
The text was updated successfully, but these errors were encountered: