vb.net - Ivalueconverter not working in phone 8.1 Xaml -


i using case converter in xaml textbox :

<textbox text="{binding obj.username,mode=twoway,converter={binding uppercaseconverter}}" grid.row="1" grid.column="0" verticalalignment="center" horizontalalignment="center" minwidth="200" x:name="usernametxtbox"/> 

and converter initiated as:

 public sub new()          ' call required designer.         initializecomponent()          ' add initialization after initializecomponent() call.         uppercaseconverter = new mccommoncodes.converters.caseconverter(mccommoncodes.converters.charactercase.lower)         me.datacontext = me     end sub property uppercaseconverter mccommoncodes.converters.caseconverter 

the code converter is:

public class caseconverter             implements ivalueconverter             property selectedcase charactercase              public sub new(byval convertcase charactercase)                 selectedcase = convertcase             end sub              public function convert(value object, targettype type, parameter object, language string) object implements ivalueconverter.convert                 dim str string = ctype(value, string)                 if not value = nothing                     select case selectedcase                         case charactercase.lower : return str.tolower                         case charactercase.normal : return str                         case charactercase.upper : return str.toupper                         case else : return str                     end select                 else                     return ""                 end if             end function              public function convertback(value object, targettype type, parameter object, language string) object implements ivalueconverter.convertback                 throw new notimplementedexception             end function         end class          public enum charactercase             lower = 0             upper = 1             normal = 2         end enum 

the problem case conversion not working, please correct me or advice have went wrong.

edit: modified xaml code converter defined static resource:

xmlns:cc="using:mcphone81.mccommoncodes.converters"  <page.resources>         <cc:caseconverter x:key="lowercaseconverter" selectedcase="lower"/>     </page.resources>     <textbox text="{binding obj.username,mode=twoway,converter={staticresource lowercaseconverter}}" /> 

code property:

property username string                                     return _usernamevalue                 end                 set(value string)                     value = value.tolower                     if not _usernamevalue.tolower = value                         _usernamevalue = value                         notifypropertychanged("username")                     end if                 end set             end property 

however text not changing case.

you can't bind converter property of binding did in

text="{binding ..., converter={binding uppercaseconverter}}" 

you should instead instantiate converter resource

<page.resources>     <local:caseconverter x:key="uppercaseconverter"/> </page.resources> 

and reference staticresource expression

text="{binding ..., converter={staticresource uppercaseconverter}}" 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -