Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how I can incorporate if statements in XAML?

I have a Main DataGrid. which i binded to a Database. but based on various button click different tables from the Database will be opened. each table have dissimilar columns although it is linked to a single database.so based on the button click I want to execute only certain XAML codes . other codes will not be active. it requires the use of an if statement. how I can approach this situation. I want to maintain only one window to boast all tables .

ie if the statement in Mainwindow.xaml.cs is <b>sql="Select*from Authors"</b>

execute this Segment<..segment1..> of satement in Mainwidow.xaml

if the statement in Mainwindow.xaml.cs is <b>sql="Select*from ISBN"</b>

execute this Segment<..segment2..> of satement in Mainwidow.xaml

any type of help will be appreaciated

thanks in advance

Iqbal
Posted
Updated 15-Jan-12 3:36am
v2

1 solution

One approach can be this :

Make a user control for every individual tables which have a grid and other facilities prepared in there. Then dynamically load that user control into the window which you want to load all controls in there.

For example you can add a StackPanel to your main window and add newly created user control to its Children based on decision made after your if statements.

Have a look at here :
http://stackoverflow.com/questions/1774962/wpf-how-do-i-load-user-controls-dynamically[^]

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900