Reputation: 11
Sorry if I ask a basic question !
Class Customer has got string Name
and int Age
In MainPage.xaml.cs I have :
ObervableCollection < Customer > Customers
In MainPage.xaml :
<Listbox x:Name = "ListCustomer"
ItemsSources = "{Binding Customers}"/>
<Button x:Name = "Button1" Visibility = "Collapsed"/>
How can i set Button1 visibility in MainPage.xaml.cs?
if(ListCustomer == null)
<-- doesn't have data Button1 is collapsed, if Listbox (or Customer - I don't know)
has got data Button1 is visibled
//or if(Customers == null)
{
Button1.visibility = visibility.visibled
}
Where i can put it ?
(in Navigation To, Navigation From, or Page_Load, some where...)
Upvotes: 0
Views: 1312
Reputation: 3217
Button1.Visibility = System.Windows.Visibility.Collapsed;
or
Button1.Visibility = System.Windows.Visibility.Visible;
The above code should help you make the button invisible and visible respectively.
It would be best if you could put it in the Loaded
event handler. This is where you can be sure that all the UI elements are loaded.
Upvotes: 2