Click here to Skip to main content
15,890,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am new to WPF.

I have label control created in vb.net by wrapping on windows .net Label class.

Now I want to migrate Label control from .net to WPF.

I am facing a problem with below properties and like to find alternatives in WPF

Label.AutoEllipse = False
Label.Autosize = False
Label.BorderStyle = Windows.Forms.BorderStyle.None
Label.Margin = New System.Windows.Forms.Padding(0)
Label.TextAlign = Drawing.ContentAllignment.TopLeft


The error being all this properties not present in label class of WPF.

Is there any alternative for text in Label class of WPF.


Thanks in advance,
Posted
Comments
Sergey Alexandrovich Kryukov 6-Nov-12 22:50pm    
Wrong approach. Read the MSDN article on the class and see what is useful for you. This question is not productive.
--SA

1 solution

Please see my answer to the question. This is where you need to start:
http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx[^].

Also consider using this UIElement as an alternative:
http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.aspx[^].

Also, I would advice to stop thinking of WPF as of "another System.Windows.Forms". Better try to embrace WPF approach, very different.

If this is not enough, this should help you much more than the above articles: Microsoft Q209354.

Please, no offense. This is a joke, but the moral of it is really useful. :-)

[EDIT]

Please see my comments below. The approaches are very different, because the concept of UIElement if very different from System.Windows.Forms.Control. There is no "translation".

Let's take the borders. There are no bordered elements in WPF. And this is because they are absolutely not needed. Let's say you want to draw a border around element. Write XAML where your element is sandwiched with one or two Border elements. Yes, that's all. And the border should be auto-sized. This is my code sample on how to create a rounded "3D-style" auto-sized border:

sample for rounded corner combobox in wpf[^].

Are you getting the idea? The approach has very little in common with Forms.

About things related to auto-sizing, you need to learn this:
http://msdn.microsoft.com/en-us/library/ms745058.aspx[^].

Again, very different, isn't it? Are you finally getting convinced? You really need to lean things pretty much from scratch. If you keep asking questions like that, you will waste too much time.

—SA
 
Share this answer
 
v4
Comments
Vijay hit 6-Nov-12 23:22pm    
Hahaa... Hey your joke is very funny...u can be a great joker. Huffff...can't control of laughing...but has lots of stuff to do.:)


Your answer holds good if I have to make application just using WPF.
But I want to use small module created with few WPF controls in my Form applcation.

I know [Autosize][Borderstyle] properties are not exist in WPF.
I wanted to know any alternative or similar property in WPF.

In my last post I got answer for Label.Content as alternative for Label.Text.

Like wise was searching for alternative method.

Please, no offense. This is NOT a joke.

Vijay
Sergey Alexandrovich Kryukov 6-Nov-12 23:56pm    
It's great that you have a sense of humor. Unfortunately, I cannot get a credit for that text; but I was probably the first who introduced a reference to it on CodeProject.

Ah... that was you who asked about Label.Text. You see, as I say, your approach to re-using your Forms code is not very productive. I really, really suggest you design it from scratch. The approach is very, very different. You are just wasting time. I'll give you some ideas... wait a minute...

--SA
Sergey Alexandrovich Kryukov 7-Nov-12 0:07am    
OK, please see the updated answer, after [EDIT].
Better now? :-)
--SA
Vijay hit 7-Nov-12 0:10am    
Yes..
Vijay hit 7-Nov-12 0:08am    
Thanks for your comment.

Yes I know reusing form is not productive. Also am suffering a lot in the process of conversion.
Designing from scratch is easy, But it is my PM's order which I can't deny.

Right now we have created almost all the controls of Form. Few controls we are planning to create in WPF. Incase, if we don't find alternative property in MSDN, we have to create our own alternative method in WPF to satisfy the same.
For Label and TextBpx almost 90% of conversion is done. Similarly trying for few other controls like DatagirdView, Combobox and Datetimepicker.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900