开发者

Styling an extended TextBox control in Windows Phone 7

Totally new to custom control creation in Silverlight.

I'm wanting a custom control that inherits from a TextBox control. I've found plenty of tutorials but they all do something like watermarked text or other attached properties. My goal is only to manipulate text at time of entry using the KeyUp event, so visually my TextBox is no different from a standard TextBox.

I created a class file and inherited from TextBox, but at run-time the textbox doesn't display. From what I can gather I need a themes/generic.xaml file, but all of samples I've seen include styles for the additional properties, and in my ignorance I don't know what to change and/or remove.

I'm hoping someone can point me to a generic plain开发者_开发问答-jane TextBox style definition or a tutorial of such.


What you described should work, I just tried the following and the TextBoxEx renders just fine:

public class TextBoxEx : TextBox
{
  protected override void OnKeyUp(KeyEventArgs e)
  {
    base.OnKeyUp(e);
  }
}

You do not need to add a generic.xaml file. This file is used to provide a template which defines the look of your control. You specify the default look of your control by setting the following property:

DefaultStyleKey = typeof(MyControl);

However, as the above TextBoxEx does not set this property, it uses the value inherited from TextBox and hence it inherits the same template (i.e look).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜