background preloader

WPF

Facebook Twitter

Threading Model. Consider the following example: This simple application counts upwards from three, searching for prime numbers. When the user clicks the Start button, the search begins. When the program finds a prime, it updates the user interface with its discovery. At any point, the user can stop the search. Although simple enough, the prime number search could go on forever, which presents some difficulties. We could conduct the prime number search in a separate thread, but then we would need to deal with synchronization issues. Microsoft Word accomplishes spell checking using this mechanism. The following example shows the XAML that creates the user interface.

The following example shows the code-behind. public void CheckNextNumber() { // Reset flag. For the complete source code for this sample, see the Single-Threaded Application with Long-Running Calculation Sample. AttachedCommandBehavior V2 aka ACB « C# Disciples. YOUAfter publishing my AttachedCommandBehavior library, (you can read about this here), some WPF Disciples recommended some new features to make the library cover more use cases. Thanks William Kempf your input was amazing! I added 2 new features - Support for Collection of binding to commands- Support for Light weight Commands or as I call them Action Support for Collection of binding to commands This is a very handy feature.

Let’s say you want to hook a command to the MouseDown but also want to hook up to the MouseEnter event, in ACB v1 you could now do this because you could only Bind one command at a time. 1: <Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" x:Name="test"> 2: <local:CommandBehaviorCollection.Behaviors> 3: <local:BehaviorBinding Event="MouseLeftButtonDown" Action="{Binding DoSomething}" CommandParameter="An Action on MouseLeftButtonDown"/> 5: </local:CommandBehaviorCollection.Behaviors> 7: </Border> This is something really cool as well.

WPF Performance Suite. Windows Presentation Foundation (WPF) Silverlight & WPF Control Browser. More than once, I’ve found myself wanting to be able to demonstrate the range of controls that are available for Silverlight and WPF and, today, I ended up in that same place and decided to do something about it. I built a very, very simple WPF application. Screenshot is below and you can install the application via ClickOnce by clicking on the picture below (note you'll need .NET Framework V3.5 Sp1 as I don't install it for you here); All it’s doing is displaying in a TreeView with a number of sections in it; WPF Built In Controls WPF Toolkit Controls WPF 3rd Party Controls Silverlight Built In Controls … and this is just driven by an XML configuration file that’s embedded into the application so if you happen to know of other sets of controls that should be included then let me know.

What’s really cool about this stuff these days is that control vendors tend to have either a; WPF XBAP Silverlight XAP on their website showcasing their controls. Because it uses the WebBrowser control; Bea Stollnitz » WPF’s CollectionViewSource. Oct 31, 2009 CollectionViewSource has existed for a long time in WPF and was recently introduced in Silverlight 3. My next post will cover CollectionViewSource in the context of Silverlight. But before covering that topic, I’ve decided to provide some background about why we introduced this class in WPF. Views in WPF When a user binds a WPF property to a collection of data, WPF automatically creates a view to wrap the collection, and binds the property to the view, not the raw collection.

This behavior always happens, and is independent of CollectionViewSource. Views provide four types of functionality: sorting, filtering, grouping and tracking the current item. The type of view created by WPF depends on the collection type. ListCollectionView -> Created when the collection implements IList.BindingListCollectionView -> Created when the collection implements IBindingList.EnumerableCollectionView -> Created when the collection implements nothing but IEnumerable.

CollectionViewSource in WPF. Search and Highlight Text in an Arbitrary Visual Tree. A while back I answered this question on stackoverflow and have been meaning to elaborate on my answer ever since with a more comprehensive blog post. The question is about how to highlight some text in the UI when the user enters some search text. I thought I’d extend the concept into a clean, generic solution as far as I could and share it here.

My requirements are pretty straightforward: Provide a search box in which the user can enter some text. Highlight all matching text in the window, regardless of where it appears in the visual tree. I was able to pull this off to an extent I am satisfied with. After an initial approach that relied on reflection in order to highlight content elements (ugh!) The basic approach I ended up using is: Traverse the visual tree recursively, looking for IContentHosts and DocumentViewerBases. There are a few problems that I’m aware of: If the matching text spans multiple lines, the bounding rectangle isn’t correctly calculated. PS. MVVM Foundation.

Using Git with Visual Studio. WPF 4.0 Text Stack Improvements - WPF Text Blog. Please note that the screenshots in this post are not displaying correctly. To view them in their full fidelity, right click on them and save them as a .PNGs. Then use your image viewing program of choice. Text Formatting API The attached property TextOptions.TextFormattingMode has been introduced to switch the text metrics used by WPF while formatting text.

. · Ideal – Ideal text metrics are the metrics which have been used to format text since the introduction of WPF. . · Display – In this new formatting mode, WPF uses GDI compatible text metrics. Here is a small code snipit of this property in action… Hello World ... Hello World ... Screenshot of the code snipit above. The above screenshot makes it hard to really get a sense for how much text quilty has been improved. TextFormattingMode Usage Both text formatting modes have their advantages and drawbacks. Ideal Mode · Large Text – As the size of text increases, the clarity issues with ideal mode text dissapate. Display Mode Text Rendering API. Word to XAML Converter.

Overlaying Controls in WPF with Adorners at Big Nick’s Blog. One of the common things that comes up on multiple projects using WPF is the ability to overlay the screen or a certain portion of it. Either to create a richer modal-type experience than a message box provides or to block access to a certain portion of the screen while an asynchronous or long running operation is happening. There are a number of ways to do this but the one I’ve settled on after tackling it on a few projects is an adorner that automatically overlays and control with any content you want. Other options include using the Popup control, which is problematic because popups are not part of the normal visual layout.

They are always on top of all other content and don’t move when you resize or move the window, at least not automatically. Another way you can do it is put everything inside a grid, and add the content you want to overlay with at the end of the Grid’s content with no Row or Column specification. Here is the rest of the class, OverlayAdorner.cs. Resizer: a WPF Control. Recently I needed to allow users to resize a WPF Popup. After implementing a non-generic solution, I decided to attempt to turn the concept into a generic WPF control. The Resizer control is a specialised ContentControl that can be used as follows: <kb:Resizer xmlns:kb=" Content </kb:Resizer> The Resizer control adds resizing behaviour to the content you place within it.

The default template uses a ResizeGrip and allows the user to drag the grip in order to resize the content. For example, here is how you might add resizing behaviour to a TextBox (XML namespace mapping assumed from hereon in): <kb:Resizer><TextBox>My TextBox</TextBox></kb:Resizer> The result is this: And the user can drag the grip to resize the TextBox: And here is how you might implement a resizable Popup: Here is the result: And after resizing: The Resizer control contains some other functionality worth mentioning: IsGripEnabled : enables / disables the resize grip (defaults to true).

Enjoy!

Drag and Drop