DCSIMG
Tips & Tricks - Essential WPF

Browse by Tags

All Tags » Tips & Tricks (RSS)

Animating ViewModel Properties instead of View Bound Properties by Tomer Shamam

Trying to animate a View property which is bound two-way to a View Model property, yields working animation but also unchanged View Model. It turns out that animating a two-way data-bound property breaks the data-binding! For example, having a line bounds to its view-model, X1, Y1, X2, Y2 properties, if you'll try to animate the Line, the line will be animated but at the same time its X1, Y1, X2, Y2 properties will left unbound. So how to fix that? Instead of animating the view, animate the view...

Customizing Windows 7 Taskbar from WPF – Part 3 (Jumplist Markups) by Tomer Shamam

In my previous posts I’ve demonstrated how to customize the Windows 7 Taskbar Jumplist with custom icons and actions. In this post I would like to show how to leverage XAML Markup Extensions to pick the right assembly name for both the application full path and icon resource full path. One real bizarre thing in the WPF Jumplist is that there is no option to initialize some Jumplist properties after created from XAML. For example: The JumplistTask application path. The only option is to create the...

Customizing Windows 7 Taskbar from WPF – Part 2 (Jumplist Custom Actions) by Tomer Shamam

In my previous post I showed how to use a native resource in a .NET application and how to pick a custom icon for Jumplist Tasks. In this post I would like to show how to activate custom actions from the Windows 7 Jumplist, exactly like Window Media Player and other applications do. Programs designed for Windows 7 can take advantage of the taskbar features for quickly activating application’s common actions even though the application is minimized. Actions could be added to both thumbnail toolbars...

Customizing Windows 7 Taskbar from WPF – Part 1 (Jumplist Custom Icon) by Tomer Shamam

Windows 7 Taskbar Jumplist takes you right to your favorite applications or frequent files related to your application running in the task bar. To open a Jump List, just right-click a program icon on the Windows 7 taskbar and the Jumplist pops up. If you look in MSDN for the WPF 4 JumpList class you’ll see a very nice code snippet which creates Jumplist tasks but uses an external DLL as the source of the tasks icons. First you should know that the WPF 4 JumpList is only a managed wrapper around the...

Running on Windows Phone 7 Emulator or real Device by Tomer Shamam

In one of the labs I’m writing for the Windows Phone Training Kit I’m using kind of GPS Emulator for simulating a geographic location (Latitude, Longitude). This simulator comes in handy when writing location aware application, and you don’t really have a GPS on the emulator. So instead of using C# pragmas for picking the correct path, knowing whether the application is running on a real device or not, there is an easy static property for checking that: if (Microsoft.Devices. Environment .DeviceType...

Saving and Loading Captured Image To and From WP7 Isolated Storage by Tomer Shamam

If you read my previous post about WP7, explaining how to use launchers and choosers, you may wonder how to capture an image using the phone camera, then saving it to the phone’s isolated storage. While it is easy to capture an image, it’s trickier to save it to the isolated storage. To capture an image you should do this: public partial class MainPage : PhoneApplicationPage { private byte [] _imageBytes; private void buttonCapture_Click( object sender, RoutedEventArgs e) { ShowCameraCaptureTask...

How to bind ToolBar items by Tomer Shamam

You have created a view-model for your ToolBar control, and you have a collection of commands exposed by the view-model as a property (Commands). Now you want to bind your ToolBar.ItemsSource with that property, so you have something like this: < ToolBar ItemsSource ="{ Binding Commands }" Height ="64" />   Of course, you want to have each command as a button, so you’ve created a DataTemplate : < DataTemplate DataType ="{ x : Type local : CommandModel }">...

<howto> Start Animation on Model property changed </howto> by Tomer Shamam

Lately I’m teaching UI designers to work with WPF, and one of my students asked me how to start an animation when model’s property changes, and this was my answer: If the animated element is part of a DataTemplate, use DataTrigger to monitor data changes and to start the animation. But if you don’t have a DataTemplate or the animated element is not part of the DataTemplate, create a Style for that element, and use a simple DataTrigger within. < Style x : Key ="PathStyle" TargetType ...

<howto>Know that you're in design time mode</howto> by Tomer Shamam

When you write markup extensions, or any other control that may work differently at runtime then design time, you may want to check if you’re in design time to pick the correct logic. In WPF, you can call the DesignerProperties.GetIsInDesignMode   attached property. In Silverlight, you may use the HtmlPage.IsEnabled property. This will work from both Blend and Cider designers. Example: if ( DesignerProperties .GetIsInDesignMode(textBox) {    return "In Design Time Mode" ;...

WPF DataGrid Search and Highlight by Tomer Shamam

In this post I would like to share with you a simple solution for searching and highlighting text in the WPFToolkit or WPF 4.0 DataGrid. The Problem Lets say for example that you have a DataGrid with several columns that may display text. Now you want to be able to search terms in these text parts. For example: Proposed Solution 1. Create an attached property of type string called SearchTerm for attaching the data-grid with the search term provided by a TextBox (see images). < TextBox x : Name...

WPF BindingEx – Runtime resolved Path by Tomer Shamam

One of my blog readers sent me an email regards how to create Binding to an object via XAML, where Path is unknown at design time. For example, you want to bind to Source.Property property, where Property is provided by another property. public partial class Window1 : Window { public Window1() { Path = "Name" ; Person = new Person () { Name = "Tomer Shamam" }; DataContext = this ; InitializeComponent(); } public string Path { get ; private set ; } public Person Person { get ;...

<howto>Add decorations to WPF shapes</howto> by Tomer Shamam

Introduction : You have a collection of shapes (or other elements), and you want to decorate each shape with one or more decoration, such as text. Solution Actually, there are several solutions. Some are straight forward, and some are more complex but flexible. I chose to describe a flexible way in which you don’t have to touch your visual tree directly from XAML. You just need to add decorations programmatically, whenever you liked to. < Canvas x : Name ="_shapes"> < Rectangle...

<howto>Replace ListView columns with rows</howto> by Tomer Shamam

Introduction : You want to present a table with a ListView , but you should display columns as rows. Problem : The only out-of-the-box view for the WPF ListView control is GridView. GridView was designed to work with columns. It displays headers and rows as two parts, using a stack layout by default. Changing the stack orientation to horizontal will not work since both the headers presenter and rows presenter are displaying children horizontally. Solution #1 : Do not use ListView. Use a ListBox with...

<howto>Create an Expander Group without Code</howto> by Tomer Shamam

Introduction : You have a collection of items and you want to display them as an expander group. Only one expander should be opened at a time. Problem : There is no expander group in WPF such as panel for RadioButton , also you don't want to write custom code, only XAML. Solution : Bind the collection of items to a ListBox . Create a DataTemplate to display each item as an expander. Bind the expander IsExpanded property to the ListBoxItem.IsSelected . Override the default ListBoxItem style so...

WPF Panel & Data Binding by Tomer Shamam

WPF Data Binding on behalf of ItemsControl provides an elegant solution for collection of data types. All you have to do is simple as: < ListBox ItemsSource ="{ Binding Path =Items}" ... /> But what if you want to bind the same collection to a Panel, let say UniformGrid , WrapPanel or other custom panel? Trying to bind the Panel.Children collection using the same technique above, results in a big ERROR! And the reason is: Panel.Children is not designed to be bind, hence Children is...
More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems