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 - WPF: Own Control Derived From TextBox

 
 
Old 07-26-2007   #1 (permalink)
hufaunder@yahoo.com


 
 

WPF: Own Control Derived From TextBox

I would like to create a specialized TextBox (WPF) that for instance
only accept integers/decimals/currency/etc. Since I want it to behave
like a TextBox but don't want to write one myself I would like to
create a user control. The idea was to derive a user control (Add
Items...UserControl) from a TextBox but Visual Studio does not let me
define a base class. I could go and change it by hand but I guess
there is a reason why MS didn't offer it in the first place.

So what is the best approach to write this custom TextBox?

Thanks


My System SpecsSystem Spec
Old 07-26-2007   #2 (permalink)
Lloyd Dupont


 
 

Re: Own Control Derived From TextBox

<hufaunder@yahoo.com> wrote in message
news:1185488480.886964.236560@d55g2000hsg.googlegroups.com...
>I would like to create a specialized TextBox (WPF) that for instance
> only accept integers/decimals/currency/etc. Since I want it to behave
> like a TextBox but don't want to write one myself I would like to
> create a user control. The idea was to derive a user control (Add
> Items...UserControl) from a TextBox but Visual Studio does not let me
> define a base class. I could go and change it by hand but I guess
> there is a reason why MS didn't offer it in the first place.
>
> So what is the best approach to write this custom TextBox?
>


What you need is a "CustomControl", the difference between "UserControl" and
"CustomControl" is that, in VS, userControl are created with a XAML file and
are not expected to be templatable, whereas CustomControl have no XAML
associated with them and are expected to be lookless.

> Thanks
>


My System SpecsSystem Spec
Old 07-26-2007   #3 (permalink)
hufaunder@yahoo.com


 
 

Re: Own Control Derived From TextBox

On Jul 26, 3:56 pm, "Lloyd Dupont" <net.galador@ld> wrote:
> <hufaun...@yahoo.com> wrote in message
>
> news:1185488480.886964.236560@d55g2000hsg.googlegroups.com...
>
> >I would like to create a specialized TextBox (WPF) that for instance
> > only accept integers/decimals/currency/etc. Since I want it to behave
> > like a TextBox but don't want to write one myself I would like to
> > create a user control. The idea was to derive a user control (Add
> > Items...UserControl) from a TextBox but Visual Studio does not let me
> > define a base class. I could go and change it by hand but I guess
> > there is a reason why MS didn't offer it in the first place.

>
> > So what is the best approach to write this custom TextBox?

>
> What you need is a "CustomControl", the difference between "UserControl" and
> "CustomControl" is that, in VS, userControl are created with a XAML file and
> are not expected to be templatable, whereas CustomControl have no XAML
> associated with them and are expected to be lookless.
>
>
>
> > Thanks- Hide quoted text -

>
> - Show quoted text -


Thanks for the reply. I did this. Then I changed the base class from
Control to TextBox. Then in my main xaml file I added

xmlns:MyNamespace="clr-namespace:Test"
....
<MyNamespace:NumericTextBox Name="myname"....></
MyNamespace:NumericTextBox>

Now the compiler complains:
1) In the XAML file: NumericTextBox cannot be a element in Grid
2) In the cs file: The name 'myname' does not exist in the current
context

I did recompile the whole project without success. Any input?

My System SpecsSystem Spec
Old 07-26-2007   #4 (permalink)
Lloyd Dupont


 
 

Re: Own Control Derived From TextBox


> Thanks for the reply. I did this. Then I changed the base class from
> Control to TextBox. Then in my main xaml file I added
>
> xmlns:MyNamespace="clr-namespace:Test"
> ...
> <MyNamespace:NumericTextBox Name="myname"....></
> MyNamespace:NumericTextBox>
>
> Now the compiler complains:
> 1) In the XAML file: NumericTextBox cannot be a element in Grid
> 2) In the cs file: The name 'myname' does not exist in the current
> context
>
> I did recompile the whole project without success. Any input?

Is NumericTextBox in the same project/assembly or in an other one?
if it's in an other one you should use instead

xmlns:MyNamespace="clr-namespace:Test;assembly=TheDLLName"

(notice the additional assembly information)
have you added the DLL in the list of DLL?


whant are the compile error messages? it's really hepful to look at them!

My System SpecsSystem Spec
Old 07-27-2007   #5 (permalink)
hufaunder@yahoo.com


 
 

Re: Own Control Derived From TextBox

On Jul 26, 4:48 pm, "Lloyd Dupont" <net.galador@ld> wrote:
> Is NumericTextBox in the same project/assembly or in an other one?
> if it's in an other one you should use instead
>
> xmlns:MyNamespace="clr-namespace:Test;assembly=TheDLLName"
>
> (notice the additional assembly information)
> have you added the DLL in the list of DLL?
>
> whant are the compile error messages? it's really hepful to look at them!


Yes, NumericTextBox is in the same project. I tried this here anyways:

xmlns:MyNamespace="clr-namespace:Test;assembly=Test"

Note, both were copied directly from what VS generated at the top in
the comment section. This is the error I am getting:

error MC3074: The tag 'NumericTextBox' does not exist in XML namespace
'clr-namespace:Test'. Line 32 Position 8.

The class looks something like this:

namespace Test
{
public class NumericTextBox : System.Windows.Controls.TextBox
{
static NumericTextBox() {...}
}
....
}

My System SpecsSystem Spec
Old 07-29-2007   #6 (permalink)
Lloyd Dupont


 
 

Re: Own Control Derived From TextBox

Well, don't know if that would be of any help, but I build a sample which do
what you tried to achieve.
It was build / compiled / tested with Orcas beta 2 (newly released)
and can be found there:
http://www.galador.net/stuff/Test.zip

--
Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com
<hufaunder@yahoo.com> wrote in message
news:1185552438.055362.302290@i13g2000prf.googlegroups.com...
> On Jul 26, 4:48 pm, "Lloyd Dupont" <net.galador@ld> wrote:
>> Is NumericTextBox in the same project/assembly or in an other one?
>> if it's in an other one you should use instead
>>
>> xmlns:MyNamespace="clr-namespace:Test;assembly=TheDLLName"
>>
>> (notice the additional assembly information)
>> have you added the DLL in the list of DLL?
>>
>> whant are the compile error messages? it's really hepful to look at them!

>
> Yes, NumericTextBox is in the same project. I tried this here anyways:
>
> xmlns:MyNamespace="clr-namespace:Test;assembly=Test"
>
> Note, both were copied directly from what VS generated at the top in
> the comment section. This is the error I am getting:
>
> error MC3074: The tag 'NumericTextBox' does not exist in XML namespace
> 'clr-namespace:Test'. Line 32 Position 8.
>
> The class looks something like this:
>
> namespace Test
> {
> public class NumericTextBox : System.Windows.Controls.TextBox
> {
> static NumericTextBox() {...}
> }
> ....
> }
>


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
GUI application unable to display info derived from registry Vista 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