WPF Auto Size ComboBox

August 31, 2010

One of the known issues with the WPF ComboBox is that its width is not set automatically to the widest element in the drop down list. This causes the width of the ComboBox to “jump” when the selected item changes.The simplest solution would be to set a Width explicitly, but this is not the “WPF way”, and will not work properly with different fonts and sizes, and generally is difficult to predict on a case by case basis. Several solutions have been proposed, as evident in StackOverflow. Some of them suggest changing the default control template of the...
tags: , , , ,
7 comments

WPF 4 Tip: Setting the Target of a Label

August 27, 2010

The WPF Label control is a full blown ContentControl that can hold anything, but is mostly useful for holding text because of its ability to use an access key (ALT + key) causing the keyboard focus to move to a specified element by setting its Target property. In WPF 3.x, you had to specify the element using a binding expression. For example:   <StackPanel Orientation="Horizontal" Margin="20">      <Label Content="_Name: " Target="{Binding ElementName=txtName}" />      <TextBox x:Name="txtName" Width="120" /> </StackPanel> In WPF 4, you just need to supply the element’s name...
tags: , , , ,
2 comments

Silverlight Quirk: Content Alignment not respected for ListBox

August 23, 2010

Silverlight and WPF have many similarities, and many differences as well. One of the subtle ones I’ve discovered is with respecting the HorizontalContentAlignment property in a ListBox. Here’s the same application, written in WPF and Silverlight with the following ListBox (bound to a collection of Book objects) and its item template:    <ListBox HorizontalContentAlignment="Stretch" x:Name="_list">        <ListBox.ItemTemplate>            <DataTemplate>                <Border BorderBrush="Red" BorderThickness="2">                    <Grid>                        <Grid.RowDefinitions>                            <RowDefinition Height="Auto"/>                            <RowDefinition Height="Auto" />                        </Grid.RowDefinitions>                        <TextBlock Text="{Binding BookName}" FontSize="20" />                        <TextBlock Grid.Row="1" Text="{Binding Author}" FontSize="16" Foreground="Blue" />                    </Grid>                </Border>            </DataTemplate>        </ListBox.ItemTemplate>    </ListBox> The results are: WPF: Silverlight: Not quite the same. For some reason, Silverlight’s ListBox template does...
2 comments

My C# 5.0/CLR 5 Wish List

August 22, 2010

C# 5.0 is probably in the works (for sure). A while back I blogged about features I’d like to see in C# 4.0. I didn’t get any of my wishes (well, maybe I got one wish in an unexpected way, more on that later). Here’s a list of features I’d love to see in the next version of the C# language and the CLR. It’s not yet Christmas, but maybe Microsoft’s Santa needs some time to make these wishes come true: operator constraints This is something I wished for with C# 4.0, but didn’t get. Well, I...
tags: , , , ,
11 comments

Frame Based Animations in Silverlight

August 11, 2010

One way to do animations in Silverlight is to make gradual changes to dependency properties. Although this is powerful and convenient, it lacks in control. For example, developing a game with Silverlight may require complex movements of “bad guys” and other background elements that are not well suited for the property-based animation. The alternative is frame-based animation. That is, every frame some change is applied to an element (such as the attached Canvas.Left and Canvas.Top properties, effectively moving the element around the containing canvas). How should this be handled in Silverlight? How would we get a notification...
one comment

Me at WebTech

August 8, 2010

The first WebTech conference is this Wednesday (the 11th of August), targeting web developers and other web authors. Technologies presented varies and are not limited to the Microsoft world. Java, PHP, Silverlight, ASP.NET, MVC, HTML, CSS and more. I will be presenting an “Introduction to Silverlight Development” session. So, if you’re a web developer/designer and have not yet been exposed to Silverlight, this is your chance to see what Silverlight is and what can you do with it. Maybe I’ll see you there!
no comments