I need to dynamically generate a set of objects including labels,
images and so on. The code below works fine for me. But the question
is, how to dynamically create even stub like MouseDown for objects?
<Label ... MouseDown="label1_mousedown">....
how to generate label1_mousedown dynamically?
////////////// my code ///////////////////////////////
string UIt = "<Grid xmlns:x='
http://schemas.microsoft.com/winfx/2006/
xaml'";
UIt += " xmlns='
http://schemas.microsoft.com/winfx/2006/
xaml/presentation'";
UIt += " Name='Grid1'>";
UIt += "<Grid.ColumnDefinitions>";
UIt += "<ColumnDefinition Width='100*'/>";
UIt += "<ColumnDefinition Width='200*'/>";
UIt += "</Grid.ColumnDefinitions>";
UIt += "</Grid>";
XElement U = XElement.Parse(UIt);
string UIStack1 = "<StackPanel Name='StackLabels'
Margin='3' xmlns='
http://schemas.microsoft.com/winfx/2006/xaml/
presentation'>";
UIStack1 += "</StackPanel>";
XElement stackNode1 = XElement.Parse(UIStack1);
string[] test = { "second", "set", "of", "items" };
stackNode1.Add(
from test1 in test
select XElement.Parse(
"<Label xmlns='
http://schemas.microsoft.com/
winfx/2006/xaml/presentation' Height='28'
HorizontalContentAlignment='Right' Name='" + test1.ToString() +
"Label'>" + test1.ToString() + "</Label>")
);
U.Add(stackNode1);
this.dynamiccontent.Content = XamlReader.Load
(U.CreateReader());