DCSIMG
howto - Essential WPF

Browse by Tags

All Tags » howto (RSS)

Exit Windows Phone Application by Tomer Shamam

Many Windows Phone developers wonders how a Windows Phone Silverlight application can be closed? The problem is that Microsoft didn’t provide any official way closing a Silverlight application, since working with the Metro style UX concept, the user should press the Back key, closing the application by himself. You can argue with me about this concept, but this is not the place for discussing it. You may read further about it here . This post is going to provide a simple and correct way of asking...

Open Links inside the WebBrowser control or outside using IE by Tomer Shamam

Windows Phone WebBrowser control is a great option for those applications that should host HTML content. Using the WebBrowser control is so simple, you just have to instantiate one and start using it by just calling the Navigate method: Code Snippet < Grid x : Name ="ContentPanel" Grid.Row ="1" Margin ="12,0,12,0"> < phone : WebBrowser Name ="webBrowser" /> </ Grid > Code Snippet webBrowser.Navigate( new Uri ( "blogs.microsoft.co.il/blogs...

Open Window, Dialog or Message Box from a ViewModel – part 2 by Tomer Shamam

In my previous post I have shown how to open a Window bound to a view-model triggered by the view, using a simple Action. In this post I'll show how to open a Window, triggered by the view-model.   Opening a window directly by the view where the view decides when a Window should be opened, is an incorrect approach since the view shouldn't make that decision. This decision belongs to the Application layer and not the Presentation layer. What if the view shouldn't be opened because...
תגים:, , , , ,

Open Window, Dialog or Message Box from a ViewModel – part 1 by Tomer Shamam

Saying that a view-model belongs to the Application layer, and the Application layer doesn't references upper layers, and must not create or use visual objects, how can I open a Window, Dialog or any kind of Message Box on-the-fly, based on some logic triggered by the view or view-model? Well, there are several options doing that, one is using kind of service which encapsulates that, providing an interface, so the view-model don't really work directly with the upper layer or WPF. This solution...
תגים:, , , , ,

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...

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 }">...

Internet via Acer Aspire 1420p 3G by Tomer Shamam

To all the lucky guys (like me :-) attended to the Microsoft PDC 09 conference last week, and won an acer touch tablet PC, here is how you can use the built-in 3G modem (yes it has such) to connect the Internet using your local cellular vendor. First, make sure that you have a data package. Now do as follows: Turn off your machine, and remove the battery Insert your USIM+ card to the sim slot (you may hear the click sound while pushing) Connect the battery and turn on your machine While logged in...
תגים:, , ,

<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 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...
More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems