First see this answer.
You likely don't want a Static
binding, which needs a static instance of the specified object in the Resources
somewhere (such as <Window.Resources>
. Since you're potentially changing the value, I would instead set the DataContext
of the RibbonComboBox
.
<RibbonComboBox IsEditable="False" DataContext="{Binding Path=DefaultSettings}">
<RibbonGallery SelectedItem="{Binding Path=profile1_papersize, Mode=TwoWay}">
<RibbonGalleryCategory ItemsSource="{Binding Path=PaperSizes}">
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonComboBox>
In your codebehind (Edit: sorry, this should be in your Model, with the necessary interface changes to expose the property, if applicable):
public YourModel : INotifyPropertyChanged
{
public YourModel()
{
// Contructor code...
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion INotifyPropertyChanged Members
public void SaveSettings()
{
// code to copy this._defaultSettings to Scanning.Properties.Settings.Default
Scanning.Properties.Settings.Default.profile1_papersize = this._defaultSettings.profile1_papersize;
Scanning.Properties.Settings.Default.OtherProperty1 = this._defaultSettings.Property1;
Scanning.Properties.Settings.Default.OtherProperty2 = this._defaultSettings.Property2;
Scanning.Properties.Settings.Default.OtherProperty3 = this._defaultSettings.Property3;
// code to save Scanning.Properties.Settings.Default
}
private static readonly List<string> defaultPaperSizes = new List<string>
{
"A4",
"B5",
"Letter",
"Legal",
};
private List<string> _paperSizes;
public List<string> PaperSizes
{
get
{
if (this._paperSizes = null) this.PaperSizes = defaultPaperSizes;
return this._paperSizes;
}
set
{
this._paperSizes = value;
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs("PaperSizes"));
}
}
private YourSettingsType _defaultSettings;
public YourSettingsType DefaultSettings
{
get
{
if (this._defaultSettings == null) this.DefaultSettings = Scanning.Properties.Settings.Default;
return this._defaultSettings;
}
set
{
this._defaultSettings = value;
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs("DefaultSettings"));
}
}
}
Edit 2: use the above edited code. You'll need to change SaveSettings
to apply the properties of this._defaultSettings
and then call it somewhere, such as in the event handler for a "Save" Button.Click
event or something.
Edit 3: You'll need to specify a List<string>
as the source for the RibbonGalleryCategory
bit.