I have a simple class that provides state codes as follows:
public class StateProvider
{
static string[] _codes = new string[]
{
"AL",
"AK",
...
};
public string[] GetAll()
{
return _codes;
}
}
My model class supporting the view looks something like this:
public class ProjectModel : ChangeNotifier
{
StateProvider _states = new StateProvider();
public ProjectModel()
{
Project = LoadProject();
}
ProjectEntity _project;
public ProjectEntity Project
{
get { return _project; }
set
{
_project = value;
FirePropertyChanged("Project");
}
}
public string[] States { get { return _states.GetAll(); } }
}
And my ComboBox XAML looks like this:
<ComboBox SelectedValue="{Binding Project.State, Mode=TwoWay}" SelectedValuePath="{Binding RelativeSource={RelativeSource Self}}" ItemsSource="{Binding States}" />
The binding works with the user interface on the object - if I select the state from the combo, the value will be transferred to the project object, and I can save it. However, if I turned off and rebooted, the value of the status code is not bound from the object to the user interface, and the combo does not display anything. Then, of course, subsequent storage returns the state value of the object.
, , ( ). State, Code FullName, SelectedValuePath DisplayMemberPath .
:
, ProjectModel . , ProjectEntity . . , Entity, . TwoWay , combobox.