Suppose your control looks like this:
<UserControl x:Class="TestApp.CustomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="50" Height="50">
<Grid x:Name="LayoutRoot" Background="BurlyWood">
<ComboBox Name="cmBox" Visibility="Visible"
HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0" Width="50" Height="30">
<ComboBoxItem IsSelected="True" Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
</ComboBox>
<TextBox Margin="0,0,0,0" Name="txBx" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
Height="20" Padding="0" TextWrapping="Wrap">
</TextBox>
</Grid>
</UserControl>
You could save and load its properties like this:
private void Diagram_SerializeControl(object sender, MindFusion.Diagramming.Silverlight.ControlNodeEventArgs e)
{
e.Handled = true;
e.Context.WriteBrush((e.Node.Control as CustomControl).Background, "Brush", e.XmlElement);
e.Context.WriteInt((e.Node.Control as CustomControl).SelectedIndex, "SelectedIndex", e.XmlElement);
e.Context.WriteString((e.Node.Control as CustomControl).Text, "Text", e.XmlElement);
}
private void Diagram_DeserializeControl(object sender, MindFusion.Diagramming.Silverlight.ControlNodeEventArgs e)
{
e.Handled = true;
XElement controlElement = e.XmlElement;
Brush brush = e.Context.ReadBrush("Brush", controlElement);
int index = e.Context.ReadInt("SelectedIndex", controlElement);
string text = e.Context.ReadString("Text", controlElement);
CustomControl control = new CustomControl();
//control.ParentNode = e.Node;
control.Text = text;
control.SelectedIndex = index;
control.Background = brush;
e.Node.Control = control;
}
If you are using more than one type of custom controls, you could save their type name, say as an attribute of the parent XElement given as an argument to those events.
I hope that helps,
Stoyan