c# - Markup extension naming -


i'm pretty sure answer no, there way name markup extension differently class implements it?

i make markup extension has relatively short name:

<textblock text="{my:ext}"/> 

but give different (longer) name on c# side:

public class myspecificmarkupextension : markupextension 

the information found naming on this page , *extension pattern, not want achieve. hoping attribute exists allow me this:

[someattribute("ext")] public class myspecificmarkupextension : markupextension 

but i've checked of attributes in system.windows.markup namespace , there no such attribute unfortunately.

is there solution problem?

the answer may have assumed nope. there no such class attribute. none know.

since mentioned have large amount of exceptions , keep xaml simple possible how have 1 extension calls others based on key.

its hiding extension behind key.

take @ this:

public class myextextension : markupextension {     public string output     {         get; set;     }      public myextextension(string output)     {         this.output = output;     }      public override object providevalue(iserviceprovider serviceprovider)     {         return this.output;     } }  public class markupextensionchooser : markupextension {     public string key     {         get;         set;     }      public stringlist param     {         get; set;     }      public override object providevalue(iserviceprovider serviceprovider)     {         if (this.key.equals("ext"))         {             return new myextextension(this.param.data[0]).providevalue(serviceprovider);         }          if (this.key.equals("ext123"))         {             // custom logic         }          if (this.key.equals("ext123123123"))         {             // custom logic         }          if (this.key.equals("ext123123123"))         {             // custom logic         }          if (this.key.equals("ext12121412423"))         {             // custom logic         }          return this;     } }  public class stringlisttypeconverter : typeconverter {     public override object convertfrom(itypedescriptorcontext context, system.globalization.cultureinfo culture, object value)     {         if (value string)         {             string val = (string)value;             return new stringlist(val.split(','));         }          return null;     } }  [typeconverter(typeof(stringlisttypeconverter))] public class stringlist {     public string[] data     {         get; set;     }      public stringlist(string[] data)     {         this.data = data;     } } 

i ended creating "chooser class" can accept parameters , based on key return necessary extension.

the typeconverter there allow having param="args1,args2,args3" in xaml.

this how example in main window looks like:

<textbox text="{local:markupextensionchooser key=ext, param='hello,world'}"/> 

hello displayed in textbox since pass param[0] myextextension.

it works fine me not sure if can use this.

the idea pretty simple in end bit of wpf tricking behind , if cannot follow let me know. ll gladly assist futher.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -