|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article

Introduction
Welcome to WPF.JoshSmith. This is not a typical CodeProject article. I am using the Web page generated for this article to host, and make publicly available, a library of classes I have created for use in Windows Presentation Foundation applications. Over time I will update this page (and the source code download) to include any new classes I've added to the WPF.JoshSmith library. Think of this as a really cheap and easy alternative to creating a full Web site just to make the assembly available to the world.
All of the major classes in WPF.JoshSmith either have an article about them here on the CodeProject, or I've blogged about them. The purpose of WPF.JoshSmith is to consolidate all of the classes I've created into one place, thus making it easier for people to have all the goodies in one assembly. In addition to providing the WPF.JoshSmith assembly, the source code download at the top of this article also contains test/demo projects for the various classes in the library. Those projects show how to use the code and what the various classes do.
All of the code in the library can be used free of charge, provided that the copyright statements in each source file remain intact. Josh Smith accepts no responsibility for any errors, loss of data, system crashes, etc. that occur as a result of using WPF.JoshSmith.
Contents
This section provides an overview of the major classes available in the library, divided up by namespaces. Click on the name of a class to open an article/blog entry which discusses it in depth.
- WPF.JoshSmith
- Adorners
- DragAdorner - A lightweight adorner which renders a visual that can follow the mouse cursor, such as during a drag-and-drop operation. Original concept taken from this blog post.
- UIElementAdorner - An adorner which can display one and only one
UIElement. The element is added to the adorner's visual and logical trees, enabling it to particpate in dependency property value inheritance, amongst other things.
- Controls
- Validation
- RegexValidationRule - A
ValidationRule-derived class which supports the use of regular expressions for validation.
- RegexValidator - A static class which provides attached properties that supply validation of the text in a
TextBox, using regular expressions. This class works in conjunction with the RegexValidationRule.
- CenteredContentControl - A
ContentControl derivative which exposes read-only dependency properties that return the element's center point (CenterX and CenterY). Those values can be used to bind another element (such as a Line) to the center of the CenteredContentControl, even if it is relocated at runtime.
- DragCanvas - A
Canvas which manages dragging of the UIElements it contains.
- SlidingListBox - A
ListBox which provides an animated slide effect when ListBoxItems are selected.
- SmartTextBox - A
TextBox with support for displaying a list of suggestions when the user misspells a word. The user presses the F1 key to display the list of suggestions.
- Data
- ValueConverters
- EnumValueToDescriptionConverter - An
IValueConverter which supports conversion from an enum value to the description of that value. If the enum value is decorated with the DescriptionAttribute attribute, its Description value is returned. Otherwise, the name of the enum value is returned.
- ValueConverterGroup - An
IValueConverter which contains a list of IValueConverters and invokes their Convert or ConvertBack methods in the order that they exist in the list. This allows for modular value converters to be "piped" together to achieve complex conversions.
- XamlToObjectConverter - An
IValueConverter which creates a .NET object from the XAML contained in an XmlElement. The object created can be used as the content of a WPF control or ui element, such as the ContentPresenter. The inner XML of the XmlElement passed to the converter must contain valid XAML.
- ServiceProviders
- UI
- ListViewDragDropManager - Manages the dragging and dropping of
ListViewItems in a ListView.
- ListViewItemDragState - Exposes attached properties used in conjunction with the
ListViewDragDropManager class. Those properties can be used to allow triggers to modify the appearance of ListViewItems in a ListView during a drag-drop operation.
- UnloadedManager - A service provider class which provides a means of releasing resources when a
FrameworkElement's Unloaded event fires. If the DataContext of the element implements IUnloadable, it's Unload method will be invoked when the elements Unloaded event fires.
Revision History
| Date |
Assembly Version |
Notes |
| November 11, 2006 |
1.0.0.0 |
Created the article.
|
| November 28, 2006 |
1.0.0.1 |
Added the CenteredContentControl and updated the source code download.
|
| January 24, 2007 |
1.0.0.2 |
Added the ListViewDragDropManager, ListViewItemDragState, and DragAdorner classes. Also fixed broken links to articles that were moved. Updated the source code download.
|
| February 1, 2007 |
1.0.0.3 |
Fixed a couple of bugs in the ListViewDragDropManager (see the article for details). Updated the source code download.
|
| February 25, 2007 |
1.0.0.4 |
Added the SmartTextBox control, and the UIElementAdorner. Refactored the DragAdorner and UIElementAdorner so that they share a base class. Used a bug fix created by William J. Roberts in the MouseUtilities class (read here for more details). Updated the source code download.
|
| April 13, 2007 |
1.0.0.5 |
Fixed a minor bug in the ListViewDragDropManager, which is described in detail at the bottom of that class's article. Updated the source code download.
|
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 42 (Total in Forum: 42) (Refresh) | FirstPrevNext |
|
|
 |
|
|
Hey Josh,
Just noticed - a few of your links here point to your old blog, now 404'd. I wanted to go look at that enum converter article and got a 404!
Just thought I'd mention it.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks Patrick. My former employer deleted my blog when I left . I've been meaning to update this article with links to new versions of the blog posts, but some of them are lost forever. Eventually I'll figure out what to do about this...
:josh: My WPF Blog[ ^] Without a strive for perfection I would be terribly bored.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
No problem Josh. Turned out what I needed to do was simpler than I thought. Good luck figuring out what to do about those blog posts
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi Josh, I'm new on WPF Recently I made a decision to develope an application which involves 3D visualization. I want to know is it easy to use 3D capability of WPF rather than using Direct3D? You know, I want to create some simple 3D shape taking advantage of light and camera.
Thank you in advance.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Majid Shahabfar wrote: Recently I made a decision to develope an application which involves 3D visualization. I want to know is it easy to use 3D capability of WPF rather than using Direct3D?
I don't know, I've never used Direct3D or done any serious WPF 3D programming.
:josh: My WPF Blog[ ^] The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it. - Michelangelo (1475-1564)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Josh
I'm still big on a Wpf.JoshSmith.BreadCrumb[^] control. That would rock.
I've got another idea for the Wpf.JoshSmith library: Wpf.JoshSmith.TaskDialog[^].
Built with WPF, we could make one that works on XP as well as Vista, whereas the Vista TaskDialog common control works only on Vista.
What do you think? Seems like it wouldn't be too difficult to build such a dialog.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Judah Himango wrote: Seems like it wouldn't be too difficult to build such a dialog.
Thanks for the suggestion. Difficulty is not necessarily a prohibitive factor, time is. I'm interested in the BreadCrumb control idea that you posted a while ago, it just hasn't made it to the top of my todo list yet.
:josh: My WPF Blog[ ^] Enjoy! Vote! Learn! Love! Save the whales! Eat raw diamonds! Do the Foxtrot in your tighty-whiteys! Start fires! Kill Martians!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I just need to learn to write WPF stuff; I could then write the damn thing myself instead of complaining to WPF god Josh Smith. 
I've tinkered with WPF a bit...I was able to modify the WPF RichTextBox to automatically underline hyperlinks. I've played with some of the various WPF document classes as well, but that's the extent of my experience.
One thing that is discouraging me from learning WPF further is the tools. I'm using Cider to play with WPF in VS, and jeez, Cider is hardly alpha quality. Makes me run back to the functional WinForms designer. 
By the way, Josh, how are you cooking up your XAML? Is that done with Cider? By hand?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Judah Himango wrote: By the way, Josh, how are you cooking up your XAML? Is that done with Cider? By hand?
I do almost all of my XAML writing by hand. The only thing that I've used Blend for is creating intricate Path objects, the kind of stuff that typing by hand would be impractical. I like hand-coding my XAML because it promotes learning and exploration.
:josh: My WPF Blog[ ^] Enjoy! Vote! Learn! Love! Save the whales! Eat raw diamonds! Do the Foxtrot in your tighty-whiteys! Start fires! Kill Martians!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok Josh, since you seem to be the resident WPF expert and I've just last night installed .NET 3.0, Expression Blend, and the Cider addin for VS2005..
Where do you recommend I go to start learning about all this? I tried making even a very simple app using these new tools and failed miserably - the development architecture and paradigms are just too different from .NET 2.0 (now, mind you, I've been programming in .NET for quite some time so I'm very familiar with the technology).
Maybe I'm just feeling a bit overwhelmed because it's all so new..
For example, I look at this example: Creating the Glass Button[^]
And I wonder how anyone could have even begun such a project. Nothing in that button uses the visual designer, it apparently is all Expression Blend.
Anyway, I ramble, but good tutorials on the technology (and that reveal how powerful XAML apparently really is - it looks like the designer is just an afterthought, now) would be wonderful...
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Patrick Sears wrote: Where do you recommend I go to start learning about all this?
That's a really tough question. WPF is huge, huge, huge. What do you want to be able to do with WPF? Make line-of-business apps? Make 3D visualizations of molecular structures? Create an animated board game with skinnable pieces and slick visual effects? Build a high-fidelity document viewing application? All of the above? None of the above?
Based on what you are looking to create, I would suggest different sources of learning material.
I realize that so far my answer has not answered anything, so let me take a step back and give some general tips and links...
NetFx3[^] is a great place to see all kinds of projects, article links, blogs, etc about .NET 3.0 (including WPF).
NetFxGuide[^] is really good too.
A while back I blogged about how to get started with WPF. Check it here[^].
I've posted quite a few WPF articles here on CP: Clickety[^].
Lastly, I highly suggest reading Adam Nathan's book 'WPF Unleashed.' Here's why...[^]
HTH
:josh: My WPF Blog[ ^] Don't you wish your girlfriend was hot like me?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Josh Smith wrote: WPF is huge, huge, huge.
Boy, you ain't kidding.
Josh Smith wrote: What do you want to be able to do with WPF?
Well, at the moment my attention is drawn most to the custom templating you're apparently able to do with the controls. Your custom TreeView was quite impressive, the ListView drag drop manager, and the sliding list box.. all quite impressive. So I think for the moment, what I'm looking for is 'skinnable and slick visual effects.' Shallow, I know, but I develop user apps and that's all users care about.. hehe.
Thanks for the 'clicketies'. I'll be buried in them for awhile..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Question:
In your intro to WPF, you state:[^]
"Another benefit of using vector graphics is it works well with high-resolution displays; something which is becoming a problem for the antiquated HWND technology as the resolution of display units improves."
I read something to the same effect on another blog, basically that WPF is not HWND based. What is the basis for this statement? Windows (Vista included) itself is still HWND based, is it not? How can the operating system fundamentally render a window without an HWND?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
If you're still interested in learning material for WPF, I've been writing a series of introductory WPF articles here on CodeProject. You can view the Table of Contents here[^].
:josh: My WPF Blog[ ^] Enjoy! Vote! Learn! Love! Save the whales! Eat raw diamonds! Do the Foxtrot in your tighty-whiteys! Start fires! Kill Martians!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hehe. I've been following them!
I've downloaded the Orcas CTP but haven't found time to install it yet. I've also noticed some syntactical differences between the XAML supported by the Visual Studio 2005 plugins and Orcas itself - some XAML tags are not supported in the VS2005 plugins.
I haven't said anything yet because I need to install Orcas to get a real picture of which are and are not supported so I can let you know.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hello Josh, I have tried attaching a scrollviewer to your dragcanvas so that I can get horizontal and vertical scroll bars when the object being dragged goes outside the canvas boundary. But it doesnt seem to work..Any thoughts. I replaced the base class of DragCanvas from Canvas to InkCanvas..I get the scrollbar/scrollviewer ,then..Should I do this..Is it a good approach..if I can set the EditingMode to None. Will this work? I am desperately seeking the scroll viewer functionality on this.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
wrote: I have tried attaching a scrollviewer to your dragcanvas so that I can get horizontal and vertical scroll bars when the object being dragged goes outside the canvas boundary. But it doesnt seem to work
It doesn't work with the regular Canvas, either. It's not an issue specific to the DragCanvas. I've never tried too hard to make it work, but I know what you're talking about.
wrote: I replaced the base class of DragCanvas from Canvas to InkCanvas..I get the scrollbar/scrollviewer ,then
That's because InkCanvas is not a Canvas, or Panel, at all! It is a FrameworkElement which hosts an ink-enabled panel within it.
wrote: Should I do this..Is it a good approach..if I can set the EditingMode to None. Will this work?
I don't see any problem with it in general.
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
|
Hello Josh, Thanks for your reply!
But I desperately need this Scrollviewer functionality on a canvas. Is there a smart way (without too much of coding) to achieve this on Canvas or your Drag canvas. Is it possible? If I inherit the Drag canvas from Inkcanvas, I do get auto scroll bars, but it seems to interfere with the 'drag' functionality of Drag canvas.
Do you recommend (if at all it works...) inheriting DragCanvas from the InkCanvas, if I were doing it JUST for the sake of ScrollViewer functionality because I am happy with the functionality drag canvas provides?
Can I somehow bind the Height and Width of the Canvas to the farthest edge of the farthest child element..by enumerating them or querying some container in the logical tree that has the co-ordinates of the whole occupied area by the child element(s) of the canvas..in a smart way?
Please suggest.
Thanks for all the Help and a superb Dragcanvas..!!
Thanks, Niru.
-- modified at 4:46 Monday 12th March, 2007
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
All of my controls in the dragCanvas have a Selected and UnSelected appearance. I want to be able to click on the dragcanvas so the currently selected object will become unselected resulting in none of the objects having a selected appearance. Is there anyway to trap a mouseup event on the dragcanvas so I could fire a custom event allowing me to run the code I need to?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hook the DragCanvas's PreviewMouseUp event and perform your selection logic there. You might want to use the DragCanvas's FindCanvasChild method to walk from the e.OriginalSource to the direct child element of the canvas.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks Josh.
I’m not sure what you mean by “Hook the DragCanvas's PreviewMouseUp event”. You have the following overrived which fires when I click on an object in the canvas, but not when I click on the canvas itself:
protected override void OnPreviewMouseUp(MouseButtonEventArgs e) { base.OnPreviewMouseUp(e);
if (isDragStarting) { // Raise event to any conumer interested in knowing that the drag is stopping EndDragEvent(); }
// Reset the field whether the left or right mouse button was // released, in case a context menu was opened on the drag element. this.ElementBeingDragged = null; }
I Added this event handler which also doesn’t fire when clicking on the canvus, but does fire when clicking on an object in the canvas:
public DragCanvas() { this.PreviewMouseUp += new MouseButtonEventHandler(TestOnMouseUp); }
void TestOnMouseUp(object sender, MouseButtonEventArgs e) { Console.WriteLine(sender.ToString()); }
How can I get code to execute when the user clicks and open-empty space in the canvas (clicks on the canvas)?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Moondaddy,
The problem is that by default the Canvas's Background property is null. An element with a null Background does not participate in the mouse input event system. Set the DragCanvas's Background to, perhaps, Brushes.Transparent and then it will raise the PreviewMouseUp event as expected.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|