473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

Jul 26 '07 #1
5 5056
<hu*******@yahoo.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.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
Jul 26 '07 #2
On Jul 26, 3:56 pm, "Lloyd Dupont" <net.galador@ldwrote:
<hufaun...@yahoo.comwrote in message

news:11**********************@d55g2000hsg.googlegr oups.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?

Jul 26 '07 #3
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!

Jul 26 '07 #4
On Jul 26, 4:48 pm, "Lloyd Dupont" <net.galador@ldwrote:
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() {...}
}
....
}

Jul 27 '07 #5
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
<hu*******@yahoo.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Jul 26, 4:48 pm, "Lloyd Dupont" <net.galador@ldwrote:
>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() {...}
}
....
}
Jul 30 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
4
by: farseer | last post by:
Is WPF going replace Winforms? Where can WPF applications run currently? Must you have .net3.0 installed?
2
by: hufaunder | last post by:
I have to present inputs (textbox, combobox, etc) that are not known during design time. In the past this was pretty simple to do. You just add a new control to the Controls property of a form. How...
3
by: moondaddy | last post by:
I'm working in a WPF windows application and am wondering if it's possible to rotate a Canvas or user control derived from Canvas. I created a user control which derives from Canvas and I need to...
6
by: Vivien Parlat | last post by:
Hello, I hope i'm posting into the good group, i found no active group around xaml. My situation is the following: I'm trying to play around xaml in the new VC# Express 2008. My "aim" (i...
2
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page...
3
by: Just_a_fan | last post by:
I have been through two books where they talk about the (almost) parallel control set for WPF and VB. They go through the small difference and talk about everything going on a form but what they...
2
by: Dean Slindee | last post by:
Is there any control in WPF which can host a WPF window? If not now, are there any plans to improve WPF to implement window hosting. Related question: is it not possible to build a MDI application...
1
by: moondaddy | last post by:
I have a c# 3.5 wpf app which uses user controls for data entry screens. These data entry screens can be nested inside of each. We can also have several ones open side by side at the same time. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.