Let's assume that I have defined two Grid
s and few TextBox
es in my XAML
. I want to put these TextBox
es in the Grid
s at runtime (I know which TextBox
should be put in which Grid
after starting the application).
I thought it would be possible to simply add a row definition to the Grid
in my C# code, however the text boxes bind to some Style
.
Maybe there is a simple solution (entirely in XAML - preferred)?
So the question is - how to dynamically fill the grid during the runtime with the items (text boxes) and the grid defined in XAML? Both items bind to some styles etc.
Thanks in advance for the replies and hints!
Cheers
I don't fully get you question, but if I understood correctly you want TextBoxes inside your grid using XAML.
If this is the case
you can do:
and then in a static resource:
HTH
Ok, so I am giving it a shot:
This is in code behind (TextBox).
You would obviously have to configure your code but this is the basic example.
You first have to remove to TextBox From it's parent control (Code makes the assumption that it's a grid).
And then you have to set the margin to 0 (or something else given that chances are if it's in a parent grid the margins might be big which will cause the control to be off screen).
Then set the controls column as well as row and then add the control to the new grid.
EDIT: Let me know if you want to customize it so that it loops through a grid and removes all the textboxes from that grid into another grid
Maybe you can achieve the result you desire by using ItemsControl.