For an in-depth learning resource, check out the Pro WPF in C# 2010 book: http://www.amazon.com/Pro-WPF-2010-Presentation-Foundation/dp/1430272058/ref=sr_1_1?ie=UTF8&qid=1339377007&sr=8-1
It includes several chapters on elements and how positioning works. I've found it to be extremely helpful and would recommend it.
If you're not interested in reading something so lengthy, I would recommend viewing the example code on MSDN for different layout controls, such as the Grid, StackPanel, and DockPanel.
The easiest way i found is taken from this book, pages 624-625.
The ViewModel should implement IDataErrorInfo
private string _newItem;
public string NewItem
{
get { return _newItem; }
set
{
if (Equals(_newItem, value)) return;
_newItem = value;
SendPropertyChanged("NewItem");
}
}
public string this[string propertyName]
{
get
{
if (propertyName == "NewItem")
{
var valid = NewItem.All(Char.IsLetterOrDigit);
if (!valid)
return "NewItem can only contain letters and numbers.";
}
return null;
}
}
It should create a nice red border around your textbox when rule fails, and you can play around with the error message the way you want, for example bind the error message to a textbox tool tip (MSDN):
It is a very up-to-date book, and I learned WPF from it in 2008. It's for beginners, but covers everything, from "what is user32, what is gdi+ and what is directx" to "how to implement your own plugin system in a WPF app". The only missing part is the MVVM pattern explanation, thought it thoroughly deals with Data-Binding concepts.
Extracted from amazon:
What you'll learn
WPF basics: XAML, layout, control essentials, and data flow
WPF applications: Navigation, commands, localization, and
deployment
Advanced controls: Custom controls, menus, toolbars, and trees
WPF documents: Text layout, printing, and document packaging
Graphics and multimedia: Drawing shapes, sound and video, animation,
geometric transformations, and imaging
(note from me) I would also add Data-Binding as a strong 'plus' of
this book
Who is this book for?
This book is designed for developers
encountering WPF for the first time in
their professional lives. A working
knowledge of C# and the basic
architecture of .NET is helpful to
follow the examples easily, but all
concepts will be explained from the
ground up.
The WPF RichTextBox, like most of the rich text controls that have preceded it, can be a bit sluggish. If you need to hold huge amounts of data, use intricate logic to handle key presses, or add effects such as automatic formatting (for example, Visual Studio’s syntax highlighting or Word’s spelling-checker underlining), the WPF RichTextBox probably won’t provide the performance you need.
For an in-depth learning resource, check out the Pro WPF in C# 2010 book: http://www.amazon.com/Pro-WPF-2010-Presentation-Foundation/dp/1430272058/ref=sr_1_1?ie=UTF8&qid=1339377007&sr=8-1
It includes several chapters on elements and how positioning works. I've found it to be extremely helpful and would recommend it.
If you're not interested in reading something so lengthy, I would recommend viewing the example code on MSDN for different layout controls, such as the
Grid
,StackPanel
, andDockPanel
.The easiest way i found is taken from this book, pages 624-625.
The ViewModel should implement
IDataErrorInfo
And the view the long version:
Or the short version:
It should create a nice red border around your textbox when rule fails, and you can play around with the error message the way you want, for example bind the error message to a textbox tool tip (MSDN):
And then just add this to the textbox:
Cheers!
i think u should read good books about CLR/C# (such as this) and more specifically about WPF (i recommend either WPF 4 Unleashed or Pro WPF in C# 2010)
also, u can find nice code samples at WPF samples
And ,finally, u should necessarily code ur own programs: more code - more experience
Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4
http://www.amazon.com/Pro-WPF-2010-Presentation-Foundation/dp/1430272058
It is a very up-to-date book, and I learned WPF from it in 2008. It's for beginners, but covers everything, from "what is user32, what is gdi+ and what is directx" to "how to implement your own plugin system in a WPF app". The only missing part is the MVVM pattern explanation, thought it thoroughly deals with Data-Binding concepts.
Extracted from amazon:
Following excerpt from MacDonald's Pro WPF in C# 2010 book, p. 966:
The WPF RichTextBox, like most of the rich text controls that have preceded it, can be a bit sluggish. If you need to hold huge amounts of data, use intricate logic to handle key presses, or add effects such as automatic formatting (for example, Visual Studio’s syntax highlighting or Word’s spelling-checker underlining), the WPF RichTextBox probably won’t provide the performance you need.