Is there any good tutorial for creating WPF controls entirely at runtime?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no such a tutorial I know of, partially because that is quite straightforward if you’ve got already your XAML definition for the control.
The correspondence between XAML code and corresponding C# code is simple.
Example:
gets into
The things you should know:
Content(as inButton‘s case), or a set of child items (as in case ofGrid).In XAML sometimes special value converters are implicitly applied; in C# code you must do it yourself. Example:
turns into
Each UI element can have only one parent element. That is, you cannot add the same element to two different parents as a child.
Bindings are defined in a quite peculiar way:
gets into
(it’s better to reference the
Containerby actual reference than by name).The syntax for attached properties is again not straightforward:
turns into
Please note that for each of the constructs/attributes you can look up in MSDN the exact way to express it in both XAML and C#, usually directly at the article describing the concept you are looking for.