473,799 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF user control

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 imagine that when i'll succeed this aim, my understanding
will be much better than now) is to create a personalized textbox,
whose background varies between : Blue (value <= 0), Yellow (value
between and 100), Red (value >= 100) or Orange (non-numeric value).

To do so I designed a UserControl, containing a TextBox (no way to
inherit from it in xaml ?), storing a converted int? value ("?"
because of cases user enters nonnumerical value), and exposing
DependancyPrope rties like "Hot", "Cold", and so on.

The code is as minimal as posible, because I want most of the work to
be done in another control, say "ColoredTextBox ", which I want formed
as the TextBoxes in example:
http://msdn.microsoft.com/msdnmag/co...spx%3floc%3dfr

Initially I couldn't only see the exposed property; now, moreover, I
have errors like "Error 1 Operation is not valid due to the current
state of the object." on a line such as
<ControlTemplat e x:Key="template TextBox"
TargetType="{x: Type my:MyNumTextBox }">,
and globally I cannot find the way to create this textbox which uses
triggers on my custom properties to change the background colors.

Can anyone tell me if the way i try to do it is wrong, or how to
achieve this little control ? My only need is that it is made using
WPF, because the interest for me is to learn it, I think I could do it
easily using WinForms.

Thank you in advance (and sorry for my English) !
Dec 3 '07 #1
6 7493
Eps
Not sure how to do it in XAML but you could suscribe to the textbox's
text changed event, then write some procedural code to change the
background of the textbox depending on its contents.

--
Eps
Dec 3 '07 #2
On 3 déc, 13:30, Eps <e...@mailinato r.comwrote:
Not sure how to do it in XAML but you could suscribe to the textbox's
text changed event, then write some procedural code to change the
background of the textbox depending on its contents.

--
Eps
Thanks for your answer, but that's what I was talking about when
saying "I think I could do it
easily using WinForms". This doesn't look like the xaml way, like in
the link. This is that way i'm trying to 'mimic'.
Dec 3 '07 #3
Hello,
I'm trying to play around xaml in the new VC# Express 2008. My "aim"
(i imagine that when i'll succeed this aim, my understanding will be
much better than now) is to create a personalized textbox, whose
background varies between : Blue (value <= 0), Yellow (value between
and 100), Red (value >= 100) or Orange (non-numeric value).
The best way to achieve this is to establish a data binding on the text-box's
Background property, binding it to the Text property of the same control
(RelativeSource pointing to self, Path pointing to Text), with a custom Converter
that converts Text into a Brush. The converter should try converting the
text into an int, and then construct a SolidColorBrush , as appropriate.

If you'd like to avoid copypasting the binding to all the textboxes around,
you could inherit a class from a TextBox (no XAML involved) and wire up the
same binding in its constructor thru the SetBinding method.

(H) Serge
Dec 4 '07 #4
On 4 déc, 02:19, Serge Baltic <balt...@hypers w.netwrote:
Hello,
I'm trying to play around xaml in the new VC# Express 2008. My "aim"
(i imagine that when i'll succeed this aim, my understanding will be
much better than now) is to create a personalized textbox, whose
background varies between : Blue (value <= 0), Yellow (value between
and 100), Red (value >= 100) or Orange (non-numeric value).

The best way to achieve this is to establish a data binding on the text-box's
Background property, binding it to the Text property of the same control
(RelativeSource pointing to self, Path pointing to Text), with a custom Converter
that converts Text into a Brush. The converter should try converting the
text into an int, and then construct a SolidColorBrush , as appropriate.

If you'd like to avoid copypasting the binding to all the textboxes around,
you could inherit a class from a TextBox (no XAML involved) and wire up the
same binding in its constructor thru the SetBinding method.

(H) Serge
Many thanks Serge, I wasn't taking this way before your answer. It
works fine, with not much code. I think I will embed this customized
textbox into a CustomControl to keep its xaml nature 'clean'.

Dec 5 '07 #5
Hello,
Many thanks Serge, I wasn't taking this way before your answer. It
works fine, with not much code. I think I will embed this customized
textbox into a CustomControl to keep its xaml nature 'clean'.
I think a CustomControl is even too much code. Just a class that inherits
from TextBox and sets the binding in its ctor. With a custom control, you'll
have to expose all of the TextBox's properties to make it usable.

(H) Serge
Dec 6 '07 #6
On 6 déc, 18:51, Serge Baltic <balt...@hypers w.netwrote:
Hello,
Many thanks Serge, I wasn't taking this way before your answer. It
works fine, with not much code. I think I will embed this customized
textbox into a CustomControl to keep its xaml nature 'clean'.

I think a CustomControl is even too much code. Just a class that inherits
from TextBox and sets the binding in its ctor. With a custom control, you'll
have to expose all of the TextBox's properties to make it usable.

(H) Serge
I think I will follow your advice. I tried to do it using xaml, and I
am still experiencing problems with using my Converter class from same
assembly, VC#2008express seems to be buggy about that...
Dec 7 '07 #7

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

Similar topics

6
11304
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
1
7589
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
6
3383
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
4
2518
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once I have exposed a public property containing the value of a textbox in a user control..how do I grab this from the calling page? I cant think of the syntax, since my page doesnt know the contents of the class (and therefore, the public...
0
3939
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
8
3027
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
0
3443
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I will do some database updates, then I will use reflection to call a method in the parent (this.page) to load the new user control. Its at this point after it loads the new user control that it throws the error "The control must be placed inside...
2
4826
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
2
15075
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
3
1927
by: Fred Chateau | last post by:
I am trying to access a user control class, for a user control that is loaded dynamically, from the containing page. I have been able to access Web controls in the user control, but so far I have been unable to expose the user control class itself. I'm guessing that I need to set up an interface, but I am not sure how to accomplish this. Here is the code that loads the user control: protected void Page_Init(object sender, EventArgs e)...
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.