moonlander moonlander - 1 year ago 111
C# Question

Extend TextBox control and change part of default style

I want to create a class library (dll file) of the WPF TextBox with extended functionality. But i want to change one part of the TextBox's default style (IsMouseOver property trigger).

I created a new WPF user control library project, deleted the generated .XAML and .cs files from it, and added a new class file. Then i derived from the TextBox class, but i don't know how to access the style XAML.

I can't figure out how this supposed to be done..

Inside my project i currently have only this .cs file, and no .XAML file:

namespace CustomControls
public class CustomTextBox : TextBox
private string customProperty;
public string CustomProperty
get { return customProperty; }
set { customProperty = value; }

Answer Source

You can do something like this

<TextBox x:Class="CustomControls.MyFolder.CustomTextBox"


Code behind

public partial class CustomTextBox : TextBox
    public CustomTextBox()

Now you can do whatever you want to do in your xaml (edit template, apply style etc), and you'll have access to it from code behind.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download