Enum as DepedencyProperty


hi,

can tell me how register dependency property of type enum? property accessable in xaml, not how expect enum (drop down, etc). , runtime throws weird exception doesn't make sense...

thanks in advance...

below generic enumtypeconverter class wrote. 

here's property using it:

    <typeconverter(gettype(enumtypeconverter(of vehicle.vehicletype)))> _
    public property type() as vehicletype
        get
            return directcast
(getvalue(vehicle.typeproperty), vehicletype)
        end get
        set
(byval value as vehicletype)
            setvalue(vehicle.typeproperty, value)
        end set
    end property

here generic enumtypeconverter:

imports system.componentmodel    public class enumtypeconverter(of t)      inherits typeconverter        public overrides function canconvertfrom(byval context as system.componentmodel.itypedescriptorcontext, byval sourcetype as system.type) as boolean          if sourcetype.equals(gettype(string)) then              return true          else              return mybase.canconvertfrom(context, sourcetype)          end if      end function        public overrides function canconvertto(byval context as system.componentmodel.itypedescriptorcontext, byval destinationtype as system.type) as boolean          if destinationtype.equals(gettype(string)) then              return true          else              return mybase.canconvertto(context, destinationtype)          end if      end function        public overrides function convertfrom(byval context as system.componentmodel.itypedescriptorcontext, byval culture as system.globalization.cultureinfo, byval value as object) as object          if typeof value is string              try                  return ctype([enum].parse(gettype(t), value, true), t)              catch                  throw new invalidcastexception(value)              end try          else              return mybase.convertfrom(context, culture, value)          end if      end function        public overrides function convertto(byval context as system.componentmodel.itypedescriptorcontext, byval culture as system.globalization.cultureinfo, byval value as object, byval destinationtype as system.type) as object          if destinationtype.equals(gettype(string)) then              return value.tostring()          else              return mybase.convertto(context, culture, value, destinationtype)          end if      end function  end class
 


Silverlight  >  Programming Silverlight with .NET – General



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607