c# - Sort elements in StackPanel alphabetically? -


I have a stackpanel in the grid and this displays a dynamic form generated by the button, I want to know How the XML code

  & lt; Stackpaneel grid Column = "0" name = "areastack panel" orientation = "vertical" background = "Template" & gt; & Lt; / StackPanel & gt; & Lt; Stackpaneel grid Column = "1" orientation = "horizontal" background = "beige" & gt; & Lt; Groupbox name = "statusgroupbox" header = "work item" width = "234" & gt; & Lt; StackPanel name = "Status StackPanel" & gt; & Lt; / Stackpanyel & gt; & Lt; / GroupBox & gt; & Lt; / StackPanel & gt;  

C # code

  Private zero loadexing array () {list & lt; String & gt; Collection = reporter Gate Coalitions (); Strings Unique = ""; Foreign exchange (archive collection in archive) {string fieldName = path.get filename (collection); If (unique. Consciousness (region name)) is continuing; Unique + = field name; Button area button = new button (); Area Button. Click + Area = Button_Click; Area Button. Margin = new thickness (2); AreaButton.Content = areaName; AreaStackPanel.Children.Add (areaButton); Field}}  

I would recommend using MVVM to accomplish this task. I am posting an example of what will work in a fairly clean fashion.

Your XML should look like this:

  & lt; Window x: class = "item template.dmoin window" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/ 2006 / xaml "xmlns: local =" clr- namespace: item templatedomo "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Window.DataContext & gt; & Lt; Local: MainViewModel / & gt; & Lt; /Window.DataContext> & Lt; Grid & gt; & Lt; ItemsControl ItemSource = "{Binding Button Description}" & gt; & Lt; ItemsControl.ItemsPanel & gt; & Lt; ItemsPanelTemplate & gt; & Lt; StackPanel & gt; & Lt; / StackPanel & gt; & Lt; / ItemsPanelTemplate & gt; & Lt; /ItemsControl.ItemsPanel> & Lt; ItemsControl.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Button margin = "2" content = "{binding name}" command = "{binding onclick commute}" & gt; & Lt; / Button & gt; & Lt; / DataTemplate & gt; & Lt; /ItemsControl.ItemTemplate> & Lt; / ItemsControl> & Lt; / Grid & gt;  

The main visual model should sort and filter your data here

  public class main viewmodel {public observable collection & Lt; Button Design & gt; Receive button description; Private set; } Public Main View Model () {Button Description = New Observation Collection & lt; Button Design & gt; (); For (int i = 0; i  

button contains attributes for button buttons

  public class ButtonDescription {Private string name; Public string name {get {return name; } Set {name = value; }} Private ICommand onClickCommand; Return to the Public ICommand OnClickCommand {onClickCommand; } Set {onClickCommand = value; }} Public Button Description () {}}  

If you are not familiar with MVVM

then I also recommend reading the following ;

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -