Silverlight Quick Tip: ChildWindow Title Customization - DevCorner

Silverlight Quick Tip: ChildWindow Title Customization

Today I discovered nice feature of ChildWindow control in Silverlight 3. I was at client’s location and been asked about the ChildWindow title customization with an icon. I had to admit, that I never tried to put something different than text and immediately looked at the type of Title property. For my surprise I found that the property is an “object”, and assumed that it could behave as a ContentPresenter/ContentControl.

After 5 minutes I had the client’s request solved:

image

My code is very simple:

<controls:ChildWindow x:Class="DevCorner.Samples.ChildWindow.SampleChildWindow"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           Width="400" Height="300" HasCloseButton="True">
  <controls:ChildWindow.Title>
    <StackPanel Orientation="Horizontal" Margin="0,2">
      <Image Source="Images/DevCorner.jpg" Width="20" Height="20" Stretch="Uniform" Margin="1,1,3,1"/>
      <TextBlock VerticalAlignment="Center">
        <Run FontSize="15" FontWeight="Bold" Foreground="Green" Text="Sample "></Run>
        <Run FontSize="10" FontStyle="Italic" Foreground="Blue" Text="Window "></Run>
        <Run FontSize="12" Foreground="Red" TextDecorations="Underline" Text="Title"></Run>
      </TextBlock>
    </StackPanel>
  </controls:ChildWindow.Title>
  <Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <TextBlock Text="This is a sample ChildWindow with customized title..."/>
    <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
    <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
  </Grid>
</controls:ChildWindow>

 

Working sample here.

 

Enjoy,

Alex

Published Thursday, September 24, 2009 4:03 PM by Alex Golesh

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: