Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - inherit controls in WPF

 
 
Old 10-09-2007   #1 (permalink)
Yoavo


 
 

inherit controls in WPF

Hi,
I have a dialog with 2 TextBox controls.
I want to add some functionality to one of the them.
I created a class MyTextBox which inherits from TextBox.
How can I connect one of the TextBox controls to my new class ?

I tried to replace the line (created automatically) in "Window1.g.cs":
internal System.Windows.Controls.TextBox YoavTextBox;

with:
internal MyTextBox YoavTextBox;

but I get compilation errors.

Yoav.



My System SpecsSystem Spec
Old 10-09-2007   #2 (permalink)
Laurent Bugnion, MVP


 
 

Re: inherit controls in WPF

Hi,

Yoavo wrote:
Quote:

> Hi,
> I have a dialog with 2 TextBox controls.
> I want to add some functionality to one of the them.
> I created a class MyTextBox which inherits from TextBox.
> How can I connect one of the TextBox controls to my new class ?
>
> I tried to replace the line (created automatically) in "Window1.g.cs":
> internal System.Windows.Controls.TextBox YoavTextBox;
>
> with:
> internal MyTextBox YoavTextBox;
>
> but I get compilation errors.
>
> Yoav.
You must not modify the g.cs file. It is generated. Your changes will be
overwritten every time you build.

If you have:

namespace HelloWorld
{
public class MyTextBox : TextBox
{
// ...
}
}


Then in your XAML code:

<hello:MyTextBox Text="Hello world"
xmlns:hello="clr-namespace:HelloWorld"/>


You can also define the xmlns:hello part in the Window if you prefer.

See also
http://geekswithblogs.net/lbugnion/a...02/107747.aspx

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Inherit from usercontrol - Object not set to instance of an object .NET General
.NET Controls .NET General
VS.NET and WPF controls .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46