How to bind ToolBar items

Thursday, July 22, 2010

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}"> <Button Command="{Binding Command}"> <StackPanel> <Image Source="{Binding Icon}" Width="32" Height="32" /> ...

Internet via Acer Aspire 1420p 3G

Sunday, November 22, 2009

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 to Windows 7 turn on the 3G modem...

<howto> Start Animation on Model property changed </howto>

Friday, November 6, 2009

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="{x:Type Path}"> <Style.Resources> ...
no comments

<howto>Know that you’re in design time mode</howto>

Tuesday, September 1, 2009

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"; }   return runtimeValue; If you don’t have the dependency object in your hand, you can pass an empty...
one comment

WPF BindingEx – Runtime resolved Path

Wednesday, August 5, 2009

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; private set; }  ...

<howto>Add decorations to WPF shapes</howto>

Tuesday, September 23, 2008

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 local:TextShapeDecoration.Anchor="0, -20" local:TextShapeDecoration.Text="Rectangle" Width="80" Height="48" ...
no comments

<howto>Replace ListView columns with rows</howto>

Monday, September 22, 2008

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 custom template. Solution #2: Create a custom ListView view, derived from the View base class...

<howto>Create an Expander Group without Code</howto>

Monday, August 4, 2008

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 it wont visualize selected state.     Code Snippet:<DataTemplate DataType="{x:Type local:Sign}"> ...

<howto>Bind an implicit generated ListBoxItem to object</howto>

Friday, July 11, 2008

I decided to post series of short howto's posts. Each post will be composed of short Introduction, Problem, Solution and a Code Snippet if relevant. Each post will be tagged as "howto".   Be my guest to read this first one.   Introduction: You have a list of data entities (vehicles) bind to a ListBox and a DataTemplate/s.     Problem: Using binding inside a DataTemplate refers to elements properties inside the data template, but you want to bind the auto generated ListBoxItem properties (Canvas.Left, Canvas.Top) to the object (XCoord, YCoord).   Solution: Create a ListBoxItem style,...
tags: ,