简体   繁体   中英

How to create only binding not null controls in xaml?

I`d like select between combobox and textbox depending on ViewModel. In the view model i have two properties one of them should be null and the other not null. enter image description here

I´m not sure if that´s exactly what you want to do. As CarbineCoder already said, some more code would be helpful. If you want to show only one of both controls you could create two properties called for example tbVisibility and cbVisibility. If you want to show the ComboBox, then cbVisibility has to be "visible" and tbVisibility has to be "hidden".

XAML would like that:

<StackPanel Orientation="Horizontal">

            <!--This is visible if tbVisibility is "visible" and cbVisibility is "hidden"-->
            <Label Width="100" Content="label" Visibility="{Binding tbVisibility}"></Label>
            <TextBox Width="184" Text="Textbox" Visibility="{Binding tbVisibility}"></TextBox>

            <!--This part is visible if cbVisibility is "visible" and tbVisibility is "hidden"-->
            <Label Width="100" Content="label" Visibility="{Binding cbVisibility}"></Label>
            <TextBox Width="184" Visibility="{Binding cbVisibility}"></TextBox>

        </StackPanel>

You only have to define in you code which property is visibile and which is not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM