I have a UserControl
that binds a property to a control, which seems to work:
<UserControl x:Class="MyUserControl" Name="control">
<TextBox Text="{Binding SomeData, ElementName=control}" />
However, fetching the information for this specific property needs another property to be set, which is set after InitializeComponent
in the main window. The constructor for my UserControl
though gets called in InitializeComponent
, causing a NullReferenceException
:
public MainWindow() {
InitializeComponent(); // <-- here my UserControl is instatiated and needs Settings
Settings = new Settings();
MyUserControl.Settings = Settings; // <-- only here do we set the Settings object (which is needed in UserControl's constructor!
}
public MyUserControl {
public string SomeData {
get {
return Settings.Get("someSetting");
}
}
}
How can I solve this? Or is my architecture wrong (just started out with WPF and data binding).