tags:

views:

52

answers:

3

I have a WPF Window style defined thusly:

        <Style
            x:Key="Applet"
            TargetType="{x:Type Window}">
            <Setter
                Property="WindowStyle"
                Value="None" />
            <Setter
                Property="WindowState"
                Value="Maximized" />
            <Setter
                Property="Title"
                Value="Hindenburg" />
            <Setter
                Property="FontFamily"
                Value="Arial" />
            <Setter
                Property="Height"
                Value="650" />
            <Setter
                Property="Width"
                Value="850" />
        </Style>

My application then defines several screens using this style (FlowWindow is just derived from Window with a few extra bits):

<uControl:FlowWindow
x:Class="KaleidoscopeApplication.DisposablesScan"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="clr-namespace:KaleidoscopeApplication"
xmlns:uControl="clr-namespace:KaleidoscopeApplication.Controls"
Style="{StaticResource Applet}"
Loaded="disposablesScanWindow_Loaded"
Unloaded="disposablesScanWindow_Unloaded">    

<Canvas>
    <!-- Top Bar Background -->
    <Image
        Source="Resources/Elements/Backgrounds/16.png" />

    text etc etc...
</Canvas>

My question - How do I define a textblock that will be displayed on every Window that uses this style? For example, if I want a logo displayed in the upper right corner of every screen...

Since the style defines things like size and font and not the content of the canvas, I'm not sure how to go about this.

Thanks in advance!

EDIT: FlowWindow is not a UserControl. It is just part of my KaleidoscopeApplication.Controls namespace. It's defined as:

public class FlowWindow : Window
{       
    public FlowWindow()
        : base()
    { }

    /// <summary>
    /// Transition smoothly to another FlowWindow.
    /// </summary>
    /// <param name="toWindow">The window to transtion to.</param>
    public override void Transition(FlowWindow toWindow)
    {
        ...
    }
}
+2  A: 

How about making a base class of the window where you can define the style for showing the logo and text box, the title using data binding. Then extend each other window in your application from the base window.

bjoshi
+1  A: 

One possibilty is to add something in the constructor of your FlowWindow. It's difficult to give a full example here because I don't know your exact design, but here is some pseudo-code:

public FlowWindow() 
    : base() 
{ 
    Image logo = new Image();
    ImageSourceConverter converter = new ImageSourceConverter();
    string path = "pack://application:,,,/Resources/logo.png";
    ImageSource source = (ImageSource)converter.ConvertFromString(path);
    logo.Source = source;
    logo.Width = 50d;

    // Add properties and attached properties like Canvas.LeftProperty,
    // Canvas.TopProperty, Canvas.ZIndexProperty, etc., and then
    // find the first child of the FlowWindow, and add the image
    // to the Children collection of that first child

} 
Wonko the Sane
+1  A: 

You can define custom Dependency Properties on your FlowWindow class, which can be set in the Style Setters. For instance, if you created a LogoImageProperty named "LogoImage", you could bind to it from the XAML like this:

<Canvas>
    <!-- Top Bar Background -->
    <Image
        Source="{Binding LogoImage, RelativeSource={RelativeSource Mode=Self}}" />

    text etc etc...
</Canvas>

This tells the FlowWindow to use itself as the binding context rather than the DataContext, but only for that particular binding.


UPDATE:

Since your FlowWindow is just a logical wrapper (and does not have any visual content), you might consider a few other possibilities:

  1. Re-use a single custom Window class for all of your windows with your standard layout/style and place your current window contents inside UserControls. Now you can host the specific UserControl via a ContentPresenter and DataTemplate on the standard Window. This works especially well if you're following an MVVM pattern and can simply pass in the view model to be visualized by your Window.

  2. You can create a new ControlTemplate for the Window with the layout you're after. See this answer for more details.

Dan Bryant
The thing is, there is no XAML file that goes with the FlowWindow class. The XAML file shown in my example corresponds to a single screen called DisposablesScan.
Tim
Ah, I see. I'll propose an alternate solution that's a bit of a design shift, but might be useful.
Dan Bryant