I had en idea, which shortly explained was that i would like to load xaml-files runtime, and then bind them to runtime data.
Inside these xaml-files i would use a component called “PropertySetter” like this:
public class PropertySetter : UserControl
{
public string Value { get; set; }
public string Text { get; set; }
public string Adress { get; set; }
public PropertySetter()
{
}
}
And the xamlfile, would look like this:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vf="clr-namespace:VisualFactory.vfGraphics.Graphics;assembly=VisualFactory">
<vf:PropertySetter Name="Datapoint" Text="propset" Value="false" Adress="10201" />
<CheckBox IsChecked="{Binding ElementName=Datapoint, Path=Value}" Content="{Binding ElementName=Datapoint, Path=Text}" />
</Grid>
I hope you get the point by now.
The checkbox would bind its values (content, ischecked) to a propertysetter, and when the application runs, it just changes the values of a bunch of “PropertySetter”‘s and the graphics update their content and values.
BUT: While the xaml correctly sets the values when it is loaded, it doesnt update them, when i change the values of the propertysetters. I have tried setting Mode=TwoWay, and the propertysetters are in a iNotify collection.
Has anyone tried something like this before?
The answer lays in the “DependencyProperty” class. I changed the PropertySetter to this:
And voilá, it all binds correctly, and i have now made a layer in between runtime loaded XAML and app-logic.