maui
maui copied to clipboard
[MAUI 8] IsVisible false is not applied on child controls
Description
If IsVisible="False" is set on a Grid then the child controls still return true for IsVisible.
On iOS this creates a bug as the keyboard "Next" button focus the invisible Entry an let the user type text into it.
Steps to Reproduce
- Create a new MAUI 8 app
- Open
MainPage.xaml.csand replace the content with:
namespace MauiApp1
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void HiddenEntry2Focused(object sender, FocusEventArgs e)
{
Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);
}
private void Entry3Focused(object sender, FocusEventArgs e)
{
Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);
}
}
}
- Open
MainPage.xamland replace the content with
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage">
<ScrollView>
<VerticalStackLayout Padding="30,0" Spacing="25">
<Entry Placeholder="entry1" ReturnType="Next"/>
<Grid IsVisible="False">
<Entry x:Name="hiddenEntry2" Placeholder="hiddenEntry2" ReturnType="Next" Focused="HiddenEntry2Focused"/>
</Grid>
<Entry Placeholder="entry3" ReturnType="Next" Focused="Entry3Focused"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
- Run the App on iOS
- Tap into the first entry and tap on the next button.
Result: Keyboard is shown for the hidden entry.
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
I tried this and was not able to reproduce this. Archive.zip
Ah, it happens on iOS when using the keyboard "next" button 😱 Seems to work with Tab on Android and Mac.
@tj-devel709 thoughts?
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
@mattleibow The keyboard "next" button is working on Android as expected but the code line
Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);
returns true on Android as well. This should be false as the parent Grid has set IsVisible="False".
@omghb no, it shouldn't be false. IsVisible on parent stops its rendering and rendering of children, but it doesn't change their properties.
@omghb no, it shouldn't be false. IsVisible on parent stops its rendering and rendering of children, but it doesn't change their properties.
@cucumber-sp That's not what I would expect. How would I find out (via code) that a Element is not visible (not rendered)?
@omghb not sure if there's a built-in solution for this, but I guess you can just go up untile parent is null, if some control has IsVisible set to false return false otherwise true. Make it and extension function and that's it
Yeah this behavior for the next button seems incorrect, I will take a look at this, thanks!
@omghb not sure if there's a built-in solution for this, but I guess you can just go up untile parent is null, if some control has IsVisible set to false return false otherwise true. Make it and extension function and that's it
@omghb I'm curious what the Visibility property would return.
For ex: var visibility = ( (IView) Content ).Visibility
https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.iview.visibility?view=net-maui-8.0#microsoft-maui-iview-visibility
@bradencohen The Visibility property returns the same value as IsVisible. The element is hidden and should be Collapsed.
@jsuarezruiz @mattleibow @omghb @omghb PR: https://github.com/dotnet/maui/pull/20154
I just tested WPF and WinUI 3 and they do not propagate the value. We don't have to follow the WPF way, but will the difference be confusing?
Anyone have any thoughts?
I am asking a question here because before we break symmetry I think we should know any decisions that were made: https://github.com/dotnet/wpf/discussions/8774
Note that WPF has Visibility and IsVisible which are fundamentally different. The former represents the intent for that particular element, the latter is read-only, calculated visibility, which I guess is "propagated" in the sense you are thinking of (i.e. you cannot have IsVisible element until all parents are visible). Does that help?
Seems that this is actually a thing, so I am thinking maybe we should do this now?
Thanks for the improvement in MAUI 8.0.10:
- #20160
Unfortunately, this fixes the issue only partly. Still not working:
- Hide an element that has the focus
- Expected: next focusable element gets the focus
- Actual: focus stays on the hidden element
- IsVisible property is not propagated to child controls