Skip to content

Fix: ensure FormItem container respects item's IsVisibleProperty #730

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VergilGao
Copy link

@VergilGao VergilGao commented Jul 16, 2025

This PR addresses an inconsistency in the visibility behavior of items wrapped by FormItem within a Form control.

Problem

When a non-FormItem control is added to a Form, it is automatically wrapped in a FormItem container. However, the Label inside this container does not bind to the item's IsVisibleProperty. As a result, even when the item is hidden (IsVisible = false), the label remains visible, which violates the expected semantics of IsVisibleProperty.

Solution

This PR enhances the CreateContainerForItemOverride method by binding the container's IsVisibleProperty to the item's IsVisibleProperty. This ensures that the entire container, including its label, correctly reflects the visibility state of the item.

Test

<u:Form
    LabelAlignment="Right"
    LabelPosition="Left"
    LabelWidth="240">
    <CheckBox IsChecked="{Binding #hiddenInput.IsVisible}" />
    <TextBox
        x:Name="hiddenInput"
        Width="300"
        u:FormItem.Label="HiddenInput" />
    <TextBox
        Width="300"
        u:FormItem.Label="Input" />
</u:Form>

@VergilGao
Copy link
Author

@dotnet-policy-service agree

@rabbitism
Copy link
Member

Semantically this is wrong. There is no way for a user to hide only the item (but not the container) after this change.

@VergilGao
Copy link
Author

VergilGao commented Jul 16, 2025

Semantically this is wrong. There is no way for a user to hide only the item (but not the container) after this change.

但是这里目前的表现是很奇怪的
如果通过附加属性设置了 label 的情况下,针对控件的隐藏并不会隐藏 label
这在表单的实际应用中会让界面显得很奇怪。
一个简单的例子:
当勾选了 checkbox 后才会显示某些表单项,我将 IsVisible 属性绑定到 checkbox 的IsChecked 上 结果当checkbox没有勾选时,表单项的输入框隐藏了但是label没有隐藏。
今天太晚了,明天有空的时候我会详细的说明一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants