The new company mainly uses WPF as a project, and has not been exposed to such things before, after a week of learning found that the layout of the WPF page, style settings and web design almost.
Both have style files that can be used to set styles uniformly for controls, even with a similar priority, and find it interesting. Here's how to add controls dynamically after the program is run.
To add a control, the container is required, and several large layout controls can be Grid Canvas uniformgrid dockpanel StackPanel WrapPanel below for an example of WrapPanel
First up code
<summary>
///methods for adding controls
///</summary>
///<param name= "Container" > Pannel class instance </ param>
///<param name= "Control" >uielement instance </param> public
static void Dynamicadd (panel Container, UIElement control)
{
Container.Children.Add (control);
}
private void Buttonadd_click (object sender, RoutedEventArgs e)
{
button btn = New button ();
Btn. Width =;
Btn. Height =;
Set a button style Use this method you must refer the resource file to the current page
btn. Style = resources["Noticebutton"] as Style;
This method can also set styles
//Get styles in App.xaml personally prefer this
//style style = (style) this. FindResource ("Noticebutton");
Sets the style
//btn for the button. style = style;
Add btn to UFG
dynamicadd (WRP, BTN);
This is the background code is very simple only when you set the style to pay attention to which method
Foreground XAML code is primarily a reference to a resource
<window.resources> <ResourceDictionary> <resourcedictionary.mergedd ictionaries> <resourcedictionary source= "/css/eventsbutton.xaml"/> </resourcedict Ionary. mergeddictionaries> </ResourceDictionary> </Window.Resources> <Grid> <grid.row definitions> <rowdefinition ></RowDefinition> <rowdefinition height= "><" /rowdefinition> </Grid.RowDefinitions> <wrappanel name= "WRP" grid.row= "0" ></wrappanel>
; <button content= "Add" grid.row= "1" height= "horizontalalignment=" Center "name=" Buttonadd "verticalalignment=" Top "width=" click= "Buttonadd_click"/> </Grid>