I am new to WPF and I find some properties of control is in text field instead of combobox in winform. For example : the columnwidth property of datagrid. I don't know why MS add this feature ? What is the advantage of it ? it makes developers harder to set the property value since we don't know what we should type in there.
WPF enables more flexibility. In addition to the old fashioned option of specifying width in pixels, you get other options. See here for details: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridlength(v=VS.95).aspx
Related
While writing a custom WPF control, I have been surprised that WPF does not provide a built-in visual editor for properties of the System.Windows.Media.Pen type. I expected to see something similar to the editor for Brush-based properties:
After examining the types of properties used to draw 'something' in some main stock WPF controls (Border, TextBlock, ListView, DataGrid, ...) I saw that they all do not have any Pen properties - only properties based on the Brush type.
Is it a general design concept of WPF and we should also avoid implementing Pen properties in our custom controls?
If implementing a Pen property is still 'eligible', can anybody show an example of doing this? Or do I need to write a property editor from scratch using the techniques described in the Creating Custom Editors section in the MSDN?
I am new to WPF. I want to design a Datagrid similar to mail list in outlook 2013 having same style and features.
In outlook 2013, Datagrid template changes when its width decreases and goes to one liner type of mode when it expands.
I tried to implement this behavior with two separate Datagrid controls (only one control will be visible at a time), however, I faced lot of issues. Changes occurred in one grid have to reflect on other grid. I think its an indirect method. Can I achieve this by using single control.
I am not sure if you are familiar with Triggers, however I would suggest you to apply a Trigger to your Style based on the control's width property and change it's style the way you wish to be.
Here is a very good tutorial about Templates and Triggers from Josh Smith that you can learn from. In fact, have a look at all the parts of this tutorial if you want to learn more about WPF best practices.
A Guided Tour of WPF – Part 4 (Data templates and triggers)
Meanwhile since you're looking for a Trigger value to be a range rather than a certain value, say (Pseudo) Trigger when ListView's width < 300, you will need to use a custom converter with your trigger.
For an example of such converter look into this question
WPF Trigger when property value is greater than a certain amount
Textbox and RichTextbox are look like same.But don't know the difference.Please tell me anyone, When i have to use TextBox and RichTextbox as well in wpf.
See this Microsoft overview of the differences between a TextBox and a RichTextBox.
From above Link:
Both RichTextBox and TextBox allow users to edit text, however, the two controls are used in different scenarios. A RichTextBox is a better choice when it is necessary for the user to edit formatted text, images, tables, or other rich content. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a RichTextBox. A TextBox requires less system resources then a RichTextBox and it is ideal when only plain text needs to be edited (i.e. usage in forms).
A RichTextBox mainly used if you want more control over styling the text color, type, font, alignment ect. So anything you can do in Microsoft Word, you can do with a RichTextBox.
It can be used to save or display .rtf files with ease.
A Textbox is basically used to display or get one line input. You can have a multi-line TextBox which is used mainly to display or get more than one one-liner and keeps you from having to
manage multiple TextBox's. Also keeps your UI a little more tidy.
So basically the main difference is in styling. If you just want something plain and simple, use TextBox. If you want something fancy, eg styles, colors use a RichTextBox.
Have a look at this:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a06ab05a-fbde-47ef-89c5-a7a57f32ffd3
A lot has been said about the differences in the controls' usage scenario.
An important technical difference is that TextBox supports DataBinding, RichTextBox does not, which makes it a bit nasty to use in an MVVM application. If you want a RichTextBox with DataBinding facilities, check out the extended WPF Toolkit on CodePlex.
Is there a list somewhere? I spent a lot of time yesterday trying to bind an ObservableCollection<string> to a RichTextBox, then when that didn't work to a FlowDocument (which I eventually found a simple work-around for). If there isn't a list is there some intellisense trick to find out? I found it really strange that FlowDocument didn't support data binding to a collection. It has a DataContext property that shows up in Intellisense so I figured there was some way to bind a collection. That coupled with the fact that supports single item binding made me certain I just couldn't find the proper property. Does everyone just eventually figure this out the hard way or did I miss something obvious?
[Edit - and the italicized text above are edits]
I guess I'm such a beginner I don't even know how to ask the question properly. I have half my answer. What I really want to know, I now realize is two things.
how do I tell which controls can be bound to a collection (the answer from below is any control that has an ItemsSource property)
When looking at a control how do I know which of the properties are dependency properties that I can bind data to? (I do realize - just now - that when I go to browser and look at each property the summary section is mentioning which properties are dependency properties. A little laborious to click on every property in a control but I can live with that if that's the easiest way to find out).
Anything that is derived from FrameworkElement (which is every WPF control to my knowledge) supports data binding. However binding a collection requires a special type of binding. You will need to bind to a ItemsControl or use a control that has the ItemsSource DependencyProperty
All WPF controls support DataBinding, on almost every property. If you post specific examples, we'll be better able to help you.
Data binding is supported on any DependencyProperty.
The target property must be a dependency property. Most UIElement properties are dependency properties and most dependency properties, except read-only ones, support data binding by default. (Only DependencyObject types can define dependency properties and all UIElements derive from DependencyObject.)
In the case of a RichTextbox or FlowDocument you can achieve binding thru the Run.Text dependency property as of .Net 4.0. But keep in mind in a RichTextBox:
Binding text to a Run object contained within RichTextBox is not supported. Editing operations within the RichTextBox may cause the binding to be cleared.
You can bind the Document property as well, however, this may require some additional logic if you need the textual data contained within.
I have a bound textbox and I need to change its associated display label to bold upon the presence of any content. I dont want to use javascript if at all possible.
Thanks
Why would javascript be involved?
Anyway, if this is really wpf, bind the FontWeight property of your label to the textbox's text property, using custom converter that converts null/empty strings to Normal font weight, and non-null/non-empty to Bold.