Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: Setting CategoryOrder via PropertyGrid PropertyDefinitions

$
0
0
Hi,

You cannot use "Properties.Settings.Default" in an attribute like :
[CategoryOrder( "C1", Properties.Settings.Default.... )
But if you define your setting in the "Settings.settings" file, like:
C1 int User 3
C2 int User 2
C3 int User 1

You can use reflection to add attributes of type "CategoryOrder" to your SelectedObject's class, like :
      var type = typeof( MyData );

      var aName = new System.Reflection.AssemblyName( "WpfApplication44" );
      var ab = AppDomain.CurrentDomain.DefineDynamicAssembly( aName, AssemblyBuilderAccess.Run );
      var mb = ab.DefineDynamicModule( aName.Name );
      var tb = mb.DefineType( type.Name, System.Reflection.TypeAttributes.Public, type );

      var attrCtorParams = new Type[] { typeof( string ), typeof( int ) };
      var attrCtorInfo = typeof( CategoryOrderAttribute ).GetConstructor( attrCtorParams );
      foreach( SettingsProperty prop in Properties.Settings.Default.Properties )
      {
        var attrBuilder = new CustomAttributeBuilder( attrCtorInfo, new object[] { prop.Name, Int32.Parse( prop.DefaultValue as string )} );
        tb.SetCustomAttribute( attrBuilder );
      }

      var newType = tb.CreateType();
      var instance = ( MyData )Activator.CreateInstance( newType );


      this.DataContext = instance;
――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF

Viewing all articles
Browse latest Browse all 2157

Latest Images

Trending Articles



Latest Images

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