-
Notifications
You must be signed in to change notification settings - Fork 746
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
CheckBox
has the same visual as false
when IsChecked
's bound value is set to null
#18629
Comments
Thanks @AndrewKeepCoding, I will take a look into investigating a bit more |
@AndrewKeepCoding I have been trying to repro the issue this morning, but I wasn't able to replicate the issue. This is my repro: <StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock AutomationProperties.AutomationId="HelloTextBlock"
Text="Hello Uno Platform!"
HorizontalAlignment="Center" />
<CheckBox Content="Sample IsThreeState CheckBox"
IsChecked="{x:Bind ViewModel.CheckBoxValue, Mode=TwoWay}"
IsThreeState="True" />
<CheckBox Content="Sample CheckBox"
IsChecked="{x:Bind ViewModel.CheckBoxValue, Mode=TwoWay}" />
<Button Content="Set to Null"
Click="Button_Click"
Margin="0,20,0,0" />
</StackPanel> public partial class MainPageVM : ObservableObject
{
[ObservableProperty]
private bool? checkBoxValue = null;
public void OnSetToNullClick()
{
CheckBoxValue = null;
}
} which results in this for both WinUI and Desktop (Skia): Do you see any adjustments I have to make to repro? Or is it specific to some other target? Thanks. |
@morning4coffe-dev I tried your project and yeah, it works. 😅 Can you check this repro project? |
I found out that you are using MainPage.xaml <Button
Click="Button_Click"
Content="Click" />
<CheckBox
IsChecked="{Binding BooleanValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsThreeState="True" /> MainViewModel.cs public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private bool? booleanValue = null;
public void DoSomething()
{
BooleanValue = BooleanValue switch
{
true => false,
false => null,
_ => true
};
}
} |
@AndrewKeepCoding Hmmm... this is interesting. I was able to run your repro project, but this is what I am seeing (left WinUI, right Skia Desktop): checkbox.mp4As this is the behavior with x:Bind on WinUI as well, I feel like the behavior is the correct one on our side and there might be issue with WinUI. What do you think @MartinZikmund? |
I'm so sorry @morning4coffe-dev . I was completely wrong. WinUI has the same behavior: Recording.2024-11-01.233122.mp4I must have used |
@AndrewKeepCoding so I guess this would be something to report on WinUI repo? Otherwise I think this can be closed |
Hey, I would like to add that there is also a problem on x:Bind. If we have focus on a checkbox, the indeterminate state is displayed, but leaving the cursor out of the checkbox (bool? = null), changes the visual state to true, even though the observable property is still null. |
Thank you for sharing. Which platform are you seeing this on? Would you be able to help me repro the issue on the sample project I shared, please? (a screenshot of the behavior you are seeing should be good) CheckBoxIndeterminate.zip Thank you. |
Forgive me, I missed to add that the problem occurs when we wrap the checkbox in a Button that performs some additional logic underneath. In the case of a simple checkbox, the problem does not occur. I realise that a better approach is to use Microsoft Behaviors, but it seems to me that this should also work in this case. I'm adding code, let me add a possible video in my free time. Xaml:
View Model:
|
Current behavior
CheckBox
has the same visual asfalse
[ ] whenIsChecked
's bound value is set tonull
.CheckBox
has the expected visual, [x] -> [-] -> [ ], with click operations.CheckBox
has the "indeterminate" visual [-] when<CheckBox IsChecked="{x:Null}" IsThreeState="True" />
.WinUI'sCheckBox
doesn't have this issue.Expected behavior
CheckBox
should have the "indeterminate" visual [-] whenIsChecked
's bound value is set tonull
.How to reproduce it (as minimally and precisely as possible)
No response
Workaround
No response
Works on UWP/WinUI
Yes
Environment
No response
NuGet package version(s)
Uno.Sdk v5.4.10
Affected platforms
Windows (WinAppSDK)
IDE
Visual Studio 2022
IDE version
Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview Version 17.12.0 Preview 4.0
Relevant plugins
No response
Anything else we need to know?
No response
The text was updated successfully, but these errors were encountered: