WPF custom textbox takes two tabs to get to text? -


i have custom textbox control displays name when there no text inside of it, curious reason have hit tab twice previous element control's text field. on first tab highlight's textbox's border. went through of levels of generic.xaml file properties window open , searching 'tab' 1 find on textbox tabstopping. how make control take 1 tab

generic.xaml:

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:supertb"> <style targettype="{x:type local:supertextb}">     <setter property="template">         <setter.value>             <controltemplate targettype="{x:type local:supertextb}">                 <border background="{templatebinding background}"                     borderbrush="{templatebinding borderbrush}"                     borderthickness="{templatebinding borderthickness}">                     <textbox text="{binding relativesource={relativesource templatedparent}, path=text, mode=twoway, updatesourcetrigger=lostfocus }" x:name="part_input">                     </textbox>                 </border>             </controltemplate>         </setter.value>     </setter> </style> 

cs:

    [templatepart(name="part_input")] public class supertextb : control {     private textbox part_input;  static supertextb() {     defaultstylekeyproperty.overridemetadata(typeof(supertextb), new frameworkpropertymetadata(typeof(supertextb))); }  public supertextb() {     loaded += supertextbloaded; }  void supertextbloaded(object sender, routedeventargs e) {     if (part_input.text == string.empty)     {         part_input.background = convertname();     } }       public override void onapplytemplate()     {         part_input = gettemplatechild("part_input") textbox;         if (part_input != null)         {             part_input.gotfocus += partinputgotfocus;             part_input.lostfocus += partinputlostfocus;         }     }      void partinputlostfocus(object sender, routedeventargs e)     {         if (part_input.text == string.empty)         {             part_input.background = convertname();         }     }      private visualbrush convertname()     {         char[] pieces = name.tochararray();         (int x = 0; x < pieces.length; x++)         {             if (pieces[x].equals('_'))                 pieces[x] = ' ';         }          string toreturn = "";          foreach (char c in pieces)             toreturn += c.tostring();          visualbrush myvis = new visualbrush();         myvis.stretch = stretch.none;         textblock mytext = new textblock();         mytext.text = toreturn;         mytext.foreground=brushes.gray;         myvis.visual=mytext;         return myvis;     }       void partinputgotfocus(object sender, routedeventargs e)     {             part_input.background = brushes.white;     }       public static dependencyproperty textproperty = dependencyproperty.register("text", typeof(string), typeof(supertextb));      public string text     {         { return (string)getvalue(textproperty); }         set { setvalue(textproperty, value); }     } } 

}

it's because have textbox within template textbox. textbox focusable, outer textbox. set isfocusable false or alter template such doesn't include textbox within it.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -