c# - radgridview change color of text between {} -


i using radgridview display string data in column. using databinding. of text strings have portions of text encased {} , display text in different color.

from looking around on net have found can change text color of text in text block im having trouble applying databound datagrid column.

could advise if possible.

---edit---

heres xaml define datacolumn:

<telerik:gridviewdatacolumn x:name="colmastervalue" header="localise - master value" datamemberbinding="{binding mastervalue}" showdistinctfilters="false" isreadonly="true"/> 

heres display: enter image description here

so want {customer.panel.field} appear in different color.

let's try next solution.

  1. will use custom textblock can separate regular character , '{' or '}'.
  2. let's add replace mechanism can replace original text decorated text. text except '{' or '}' colored in way.

here xaml code:

                <telerik:gridviewdatacolumn datamemberbinding="{binding path=text}"                                         header="headername"                                         isfilterable="false" isreorderable="false">                 <telerik:gridviewdatacolumn.celltemplate>                     <datatemplate datatype="flowconfiguration:somedatatype">                         <modules:mytextblock text="{binding text,                                  updatesourcetrigger=propertychanged}"/>                     </datatemplate>                 </telerik:gridviewdatacolumn.celltemplate> 

here mytextblock code

public class mytextblock:textblock {     private dependencypropertydescriptor _descriptor;     private bool _isupdating;      public mytextblock()     {         this.unloaded += onunloaded;         _descriptor = dependencypropertydescriptor.fromproperty(textproperty, typeof(textblock));         _descriptor.addvaluechanged(this, onvaluechanged);     }       private void onvaluechanged(object sender, eventargs eventargs)     {         if(_isupdating) return;         _isupdating = true;         var text = text;         if(string.isnullorempty(text)) return;          inlines.clear();         updateinlines(text);         _isupdating = false;     }      private void updateinlines(string text)     {         //text = @"{customer.panel.field}";         var runs = new list<run>();         var sb = new stringbuilder();         foreach (var current in text)         {             if (current.equals('}') || current.equals('{'))             {                 if (sb.length == 0)                 {                     runs.add(new run                     {                         text = current.tostring()                     });                 }                 else                 {                     runs.add(new run                     {                         text = sb.tostring(),                         foreground = brushes.red                     });                     runs.add(new run                     {                         text = current.tostring()                     });                     sb.clear();                 }             }             else             {                 sb.append(current);             }         }         if(sb.length > 0)             runs.add(new run{text = sb.tostring(), foreground = brushes.red});         runs.foreach(run =>              inlines.add(run));     }       private void onunloaded(object sender, routedeventargs routedeventargs)     {         this.unloaded -= onunloaded;         _descriptor.removevaluechanged(this, onvaluechanged);     }   } 

regards.


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? -