![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| GUI application unable to display info derived from registry | Vista General | |||