Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: Problem with Propertygrid and fonts

$
0
0
Hi Mark,

From what I understand, you want to see the new Font modified in the propertyGrid. I added a button and when clicked, the Font of the PropertyGrid.SelectedObject is modified :
Preferences pref = null;
pref = new Preferences();
_propertyGrid.SelectedObject = pref;

private void Button_Click_1( object sender, RoutedEventArgs e )
 {
      pref.EditorFont = new WpFFont( new FontFamily( "Arial" ), 17F, FontWeights.Bold,
                                               FontStyles.Italic, FontStretches.Normal );
 }
You have 2 options to reflect the changes in the propertyGrid:
Option 1)
You can call "_propertyGrid.Update()" right after the assignment of pref.EditorFont in the Button_Click_1 method. This will force an update of all properties in the propertyGrid.

Option 2)
The "Preferences" class can implement the interface "INotifyPropertyChanged" and look like this :
 public class Preferences : INotifyPropertyChanged
  {
    private WpFFont _editorFont = new WpFFont( new FontFamily( "Segoe UI" ), 9.75F, FontWeights.Normal,
                                               FontStyles.Normal, FontStretches.Normal );

    [Category( "Editor" ),
    DisplayName( "Font" ),
    Description( "The font used for the editor." )]
    public WpFFont EditorFont
    {
      get
      {
        return _editorFont;
      }
      set
      {
        _editorFont = value;
        this.OnPropertyChanged( "EditorFont" );
      }
    }

    #region INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged( string name )
    {
      if( PropertyChanged != null )
      {
        PropertyChanged( this, new PropertyChangedEventArgs( name ) );
      }
    }
    #endregion
  }
This way, the PropertyGrid will be notified of a propertyChange on its selectedObject and will update.

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>