How to change the layout of a WPF control from outside of that control

I am developing code for the service / data layer of my applications. I would really like to generate some basic WPF controls, data templates, or some other XAML based on the metadata I use to create my service / data layer. EDIT: This generation runs before compilation time.

What I present is the ability to generate a control that has basic controls in it: TextBlocks, Labels, Date Pickers, Textboxes, Checkboxes, etc. based on my data types.

The big thing I'm missing is somehow never touching the generated XAML and having complete control over the look and feel. In the web world, I could technically do this by creating "semantic" html and then using CSS selectors to select the nodes and place them. With CSS / HTML, I could completely change the layout and never touch the generated html.

Is there any control or data template control in WPF outside of this code? (Selectors, visual inheritance, etc.?)

Thank! John

0


source to share


3 answers


Use Grid.SetColumn( UIElement, value )

and Grid.SetRow( UIElement, value )

.



+2


source


If I understand correctly, you want to generate the XAML dynamically, then parse it and use it?

If so, you can parse / load it into memory using System.Windows.Application.LoadComponent (Uri uri). OR you can use XamlReader.Load (...).



Edit (read the question again, adding some stuff): You can use WPF styles to position and control the position of these elements.

0


source


You can change styles (and even ControlTemplates) in WPF dialogs using resources: If resources (at any level, such as an application) contain a style with TargetType = TextBox, it will affect all text boxes in the control that do not explicitly indicate rejecting style. Alternatively, you can tell your UserControl to use specific style keys (StaticResource) and then decide which DataTemplate you include for those style keys. Just select DataTemplate-ResourceFiles where DataTemplates use the correct keys and bundle them into your Application-Resources. If you change resources in this way, your generated code will honor those changes at runtime.

You can even change the resources at runtime, but your question reads as if this is optional.

0


source







All Articles