www.planet-xaml.net
 
  • [MIX08]

    Live Mesh Trailer

    by Florian Krüsch, September 23, 2008

    Here's a direct link to the Live Mesh trailer featured on the Software plus Services overview page on microsoft.com. It even features an Apple and MacOS X. The link is easy to find, there's a little Silverlight JavaScript that pulls an xml file with the video urls.

    A couple of years ago I had to get my head around Grid Computing at university. I dismissed the concepts as purely academic. It's fascinating to see pretty much the same technology about to become totally mainstream.

    The "Grid" in grid computing is an analogy to the electric power grid. Computing power, storage, identiy services... it will be, well, just out there, ready for your app to be plugged in to.


    no comments
  •  ^
  • [WPF]

    Waiting until a template is loaded in WPF

    by Florian Krüsch, September 18, 2008

    I ran into this while implementing a dialog inside a Popup. Popups are interesting, because they are part of the logical and visual tree, yet they render into a different HWND. Anyway, the problem was I needed to give the dialog keyboard focus when it opens, but at that time the control template isn't even expanded yet.

    Looking at Ben Carters excellent ScrollViewer Preview ToolTip I found a neat way to handle this and wrapped it into an extension method:

    C#toggle
    public static class Extensions
    {
       public static void InvokeWhenLoaded<T>(this T obj, Action action) 
          where T : DependencyObject
       {
          obj.Dispatcher.BeginInvoke(action, DispatcherPriority.Loaded);
       }
    }
    // Usage:
    if (isOpen) 
       win.InvokeWhenLoaded(() => win._dialog.Focus());

    Basically this adds the action into the Dispatcher Queue which will invoke it the next time the Dispatcher is finished loading controls. At this time the template is expanded and you can savely set focus on child elements.

    If you thought Dispatcher.BeginInvoke is just about UI-thread marshalling you're as wrong as I was :)

    Cheers,
    Florian


    no comments
  •  ^
  • [XAMLWPF]

    Binding Position Data to an ItemsHost for Layout

    by Florian Krüsch, July 21, 2008

    Edit: Actually Dr.WPF already showed what I was trying to explain here at the end of this post.

    Dr.WPF has added another awesome episode to his continuing ItemsControl saga.

    In the Bonus section he explains how to bind to the ItemContainer from within the ItemTemplate. This reminded me of something... from time to time I ran into the need for exactly the opposite thing: binding to the Item itself from within the ItemContainer.

    The scenario I'm talking about is when the list item contains some kind of position information and you want that to influence the ItemContainer's layout position within the ItemsHost.

    That is, you want a ListBoxItem to show at a position that comes from the object it displays.

    Here's a simple solution:

    Sample data:
    C#toggle
    theListBox.ItemsSource = new[]
    {
        new { Title = 
    "Hello", Pos = new Point(200,30) },
        new { Title = 
    "World", Pos = new Point(100,60) }
    };

    XAML:
    XAMLtoggle
    <ListBox x:Name="theListBox" Width="240" Height="300" Background="Black">
        
        
    <ListBox.ItemTemplate>
            
    <DataTemplate>
                
    <TextBlock Text="{Binding Title}" Background="Pink" />
            
    </DataTemplate>
        
    </ListBox.ItemTemplate>
        
        
    <ListBox.ItemsPanel>
            
    <ItemsPanelTemplate>
                
    <Canvas />
            
    </ItemsPanelTemplate>
        
    </ListBox.ItemsPanel>
        
        
    <ListBox.ItemContainerStyle>
            
    <Style>
                
    <Setter Property="Canvas.Left" Value="{Binding Pos.X}" />
                
    <Setter Property="Canvas.Top" Value="{Binding Pos.Y}" />
            
    </Style>
        
    </ListBox.ItemContainerStyle>
    </
    ListBox>

    Cheers,
    Florian


    no comments
  •  ^
  • Congratulations, Josh, to your 50th article on the Codeproject... that's quite impressive indeed!

    I do think, however, there is a much simpler solution in this case, which is truely along the WPF way of things without hackery.

    Accessing stuff inside Resource Dictionaries from within a ValueConverter is something I stumbled upon over and over again in XAML. My solution is a combination of MultiBinding and an IMultiConverter. The first Binding resembles the original binding. The second Binding binds to the FrameworkElement that provides the Resource Dictionary scope for the resource.

    In this case, I've added the type of the enum as a ConverterParameter for a generic solution:

    This is how the Binding looks like:

    XAMLtoggle
    <ItemsControl x:Name="_personList">
      
    <ItemsControl.ItemTemplate>
        
    <MultiBinding 
         
    Converter="{StaticResource EnumTypeKeyResourceConverter}" 
         
    ConverterParameter="{x:Type local:DisplayDetailLevel}"
        
    >
          
    <Binding Path="Value" ElementName="_detailLevelSlider" />
          
    <Binding ElementName="_personList" />                        
        
    </MultiBinding>             
      
    </ItemsControl.ItemTemplate>
    </
    ItemsControl>

    The code for the ValueConverter is a little bit more, mostly because of the generic number and enum conversion stuff:

    C#toggle
    public class EnumTypeKeyResourceConverter 
        : IMultiValueConverter
      {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
          if (values.Length < 2) 
                return Binding.DoNothing;

          Object value = values[0];
          var scope = values[1] as FrameworkElement;
          var enumType = parameter as Type;

          if (scope == null || enumType == null)
                return Binding.DoNothing;

          if (!enumType.IsEnum)
                return Binding.DoNothing;
                
          
    // Parse number

          Double d;
          if (!Double.TryParse(System.Convert.ToString(value), out d))
                return Binding.DoNothing;

          
    // to int.. 
          Int32 n = System.Convert.ToInt32(Math.Round(d));

          
    // to enum
          if ((!Enum.IsDefined(enumType, n)))
                return Binding.DoNothing;

          var key = Enum.ToObject(enumType, n);
          Object resource = scope.TryFindResource(key);

          return resource == null ? Binding.DoNothing : resource;
        }

        public object[] ConvertBack(object value, 
                                    Type[] targetTypes, 
                                    object parameter,
                                    CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    Cheers,
    Florian


    no comments
  •  ^
  • I've updated my article on the textured triangle control for the new Beta 2 of Silverlight 2. Luckily, only a few changes were necessary:

    OnApplyTemplate has become public, the PropertyChangedCallback must be wrapped into PropertyMetaData for DPs and, XAML-wise the TileMode set on the ImageBrush had to go.

    The greatest positive surprise in Beta 2 to me is the Visual State Manager addition. I'm very happy with what Microsoft is doing here. Tackling the complexity of the WPF/Silverlight stack by adding higher levels of abstraction is really key for the platform to get wider acceptance, especially among designers.
    Chris Schormann has a bunch of valuable posts about VSM.

    I'm thinking about another article on The Codeproject, bringing Silverglobe (still Beta 1) and textures together. I have a prototype running already.

    Cheers,
    Florian


    3 comments
  •  ^
 

Language | Sprache

All[e]  |  english  |  deutsch
Tags
 

Profile

Florian Kruesch

I am working as a freelance software architect, developer and consultant in Düsseldorf, Germany.

My focus is on Microsoft technologies and .NET 3.0, especially WPF, ASP.net and SQL Server.

I've been a lead programmer on the WPF development of the OTTO Vista Store at SinnerSchrader Studios.

My client list includes DHL, LG and Ogilvy Interactive.