-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Discussion: Visibility enum vs. IsVisible bool #5206
Comments
|
WPF's So I think Avalonia's choice to use a
Another alternative is to have both |
Agree with the sentiment. I guess the first question is: should Using the enum does add some complexity but BoolToVisiblity is a standard converter these days. Since the Visibility in UWP IS a boolean state as you mentioned it is also possible to automatically map to a bool during XAML compilation and remove the need for a converter.
An additional problem aside from a boolean is the name of the property itself. What is Avalonia's plan for an equivalent property to WPF's IsVisible? That is a point of confusion as well for those coming over from that framework. A property of the same name does something different. It is also a missing feature in Avalonia.
Another idea I heard was to add both, but mark Visibility as [Obsolete]. In terms of what happens if both get set, this isn't possible I think? The UI and dependency property system is single threaded and the last property set will apply. Perhaps you mean the circular dependency problem? |
|
It has been requested to add this to WinUI microsoft/microsoft-ui-xaml#674. A lot of more advanced cases could use this (especially considering x:Load isn't in Avalonia right now). Granted the cases where it's needed are not simple apps but places where performance is critical. I wouldn't underestimate the long-term need of an equivalent for this in Avalonia based on personal need. Edit: Although another simply case this could be used is implementing 'ScrollIntoView' functionality in customized UI scenarios.
Interesting, I am not familiar with this concept and don't believe it exists in WPF/UWP. If there is documentation on how this works I would be curious to read up on it. That said, it seems it could be handled by simply making the existing IsVisible a higher priority than Visibility. Then put in the docs that Visibility is only for backwards compatiblity and developers are strongly urged not to mix the two in code. |
@robloo how x:Load is related to WPF.IsVisible? First is about control presence in the visual tree, and second is more about rendering state (is it actually rendered or not). Anyway, WPF naming here isn't really ideal either. In the WinUI discussion there are better proposals such as IsCurrentlyRendered. |
Also if x:Load can replace WPF.IsVisible in some cases, it should be easier to implement (assuming that we would like to avoid breaking changes with IsVisible/Visibility props). |
Perhaps I didn't word that very well. As you said, x:Load cannot replace IsVisible in most cases. However, it is useful to lazily load the UI. This can be used in place of the VisibilityChanged event and IsVisible=true check before starting up some more performance-intensive parts of the UI. Again, this is relevant in cases like scrolling or when switching between views. When you discover you need this type of performance optimization you really need it. Granted most apps aren't doing something this intensive. |
Agree a better name could be found. Compatiblity would then be a concern but much less of one since this property is used much less in actual code. |
Also an interesting quote from one of Microsoft's own devs that worked on WPF I believe and is still involved in WinUI. Just some history on
|
We might want to somehow extend the property system to have "proxy" properties that aren't don't have their own storage and just map to another property with converter applied. If we've had something like that, adding an [Obsolete] Visibility property would be trivial. |
You could use corce callback. |
This would definitely be the safest approach. Managing a property like this without a single source of truth can open up a lot of unforeseen problems or complications. This idea may also be general-purpose enough to use in other scenarios not yet discussed. I'm not sure if anyone has an idea in mind of how to implement this type of proxy property though? Edit: Callbacks/actions similar to coercion may not be a bad idea. It should be separate from coercion though. We could consider something like a DataProvider from UWP's drag/drop. (It's similar but not exactly what we are looking for, if nothing more I like the name). Anyway, this would likely be useful for a number of other cases as well. A DataProvider would need to define a SetValue action and GetValue action (possibly consider supporting something like IValueConverter as well). If a DataProvider exists for a property, those actions are run to get/set the value instead of using the framework's systems. These actions are used even during binding. Aside from that, it would be quite general purpose. It could forward to another property if needed or even get data from another location. |
Just an idea below. An IValueProvider could be provided during construction of a PropertyMetadata class within a Styled/DirectProperty just like a coercion callback is. Also, coercion should apply:
public interface IValueProvider<T>
{
public T GetValue(...);
public void SetValue(T value, ...);
}
// Default implementation
public class ValueProvider<T> : IValueProvider<T>
{
public Action<T> SetValueAction { get; set; }
public Func<T> GetValueAction { get; set; }
public T GetValue()
{
return (GetValueAction != null ? GetValueAction.Invoke() : default(T));
}
public void SetValue(T value)
{
SetValueAction?.Invoke(value);
}
} The above is just an idea to keep the discussion moving. Changing the signatures to something more like coercion has right now should be considered. |
Would someone be kind enough to move this to Discussions? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Is your feature request related to a problem? Please describe.
All other XAML-based frameworks (WPF, UWP, WinUI) use an enum to set the visibility of a control. In the interest of code-compatiblity, should Avalonia support this enum as well?
In WPF:
In UWP/WinUI:
As can be seen, UWP dropped support for the Hidden value. I would guess
Hidden
wasn't used much in real-world apps to warrant it being carried over from WPF. This means, in UWP, the property is equivalent to a bool which is what Avalonia has done from the beginning:Avalonia:
Describe the solution you'd like
Control visibility, like DependencyProperty, is one of the subtle changes that creates significant headache using Avalonia from existing windows code. It necessitates creating a lot of conditional code in places where clean MVVM isn't already used (in that case only the converters change). It can affect nearly every part of the UI. It would be great to discuss some solutions:
Control.Visiblity
and the corresponding enum to Avalonia could be done in some proposed compatiblity layers using something like an attached property. This would mitigate concerns with having two properties that do the same thing in Avalonia itself.IsVisible
could be removed from Avalonia and replaced with the WinUI equivalent -- which is a lot of breaking changes for existing Avalonia code.IsVisible
is removed from Avalonia as it exists now, it could be replaced with the get-only property of the same name from WPF UIElement.IsVisible. WPF's property tells applications if a control is actually visible in the UI. This, along with its corresponding event, is especially useful to tracks when items are scrolled out of view for example.Describe alternatives you've considered
The alternative is simply to use Avalonia's existing convention.
Additional context
Originally discussed here but broken up into separate issue.
The text was updated successfully, but these errors were encountered: