Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make default visibility collapsed when there is no binding element

Tags:

wpf

xaml

I have a user control with textbox and button which are bound to properties from viewmodel.

    <Grid>
        <StackPanel>
            <TextBox Text=" Hi" IsEnabled="{Binding IsReadOnly, UpdateSourceTrigger=PropertyChanged}"></TextBox>
            <Button Content="B" Visibility="{Binding IsVisible, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}"></Button>
        </StackPanel>
    </Grid>

How to make the button invisible when the datacontext is not provided for this usercontrol?

like image 335
user3013076 Avatar asked Mar 11 '26 09:03

user3013076


1 Answers

FallbackValue

<Button Content="B" Visibility="{Binding IsVisible,
                                 UpdateSourceTrigger=PropertyChanged,  
                                 Converter={StaticResource BooleanToVisibilityConverter}}, 
                                 FallbackValue=Collapsed"></Button>
like image 185
paparazzo Avatar answered Mar 13 '26 23:03

paparazzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!