wpf - Label with static text and binding -


i trying label show specific text while being bound variable in vb.net code. can make binding cant add static text.

what have far:

<label x:name="testlabel" content="{binding path=row, stringformat='row #{0}'}"                            horizontalalignment="left"                            height="35"                            margin="203,21,0,0"                            verticalalignment="top"                            width="83"                            fontsize="18"> 

with

public class row     implements inotifypropertychanged      private _row byte     public property row() byte                     return _row         end         set(byval value byte)             _row = value              onpropertychanged(new propertychangedeventargs("row"))         end set     end property      public event propertychanged propertychangedeventhandler implements inotifypropertychanged.propertychanged      public sub onpropertychanged(byval e propertychangedeventargs)         if not propertychangedevent nothing             raiseevent propertychanged(me, e)         end if     end sub end class 

and

private rows new row  public sub new()     initializecomponent()     testlabel.datacontext = rows     rows.row = mytextbox.text.handledstringtosbyte end sub 

the extension code (since have custom extension):

''' <summary> ''' handles conversion of string variable tiny integer ''' </summary> ''' <param name="s"></param> ''' <param name="i">returned if conversion fails.</param> ''' <returns>signed 8bit integer</returns> ''' <remarks></remarks> <runtime.compilerservices.extension()> _ public function handledstringtosbyte(byref s string, optional sbyte = 0) sbyte     try         if s = string.empty             return         else             return sbyte.parse(s)         end if     catch         dim result string = string.empty         dim returnbyte sbyte         dim parsed byte         each character in s.tochararray             if character = "-"                 if s.substring(0, 1).tostring <> "-"                     exit                 end if             end if             if character = "."                 exit             end if             if byte.tryparse(character, parsed)                 result = result + parsed.tostring             end if         next         if result <> string.empty             if sbyte.tryparse(result, returnbyte)                 return sbyte.parse(returnbyte)             else                 if short.parse(result) > short.parse(sbyte.maxvalue.tostring)                     return sbyte.maxvalue                 elseif short.parse(result) < short.parse(sbyte.minvalue.tostring)                     return sbyte.minvalue                 else                     return sbyte.parse(returnbyte)                 end if             end if         else             return         end if     end try end function 

now thought using stringformat in binding add static text , place bound variable {0} spot gives me bound variable in label.

what doing wrong?

binding target content property object type, why cannot use stringformat binding.

instead use contentstringformat property

<label content="{binding path=row}"          contentstringformat="row #{0}" /> 

another approach: create readonly property in viewmodel represent value in wanted format

private _row byte public property row() byte             return _row     end     set(byval value byte)         _row = value         onpropertychanged(new propertychangedeventargs("row"))         onpropertychanged(new propertychangedeventargs("rowtext"))     end set end property  public readonly property rowtext string             return string.format("row #{0}", me.row)     end end property 

then bind property view

<label content="{binding path=rowtext}"/> 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -