tags:

views:

156

answers:

2

Hello,

I have application where default Window's borders switched off

Window tag definition looks like this:

<Window x:Class="TEA.UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Title" WindowStyle="None" AllowsTransparency="True" Background="Transparent">

Inside Window tag, there is Grid panel, it contains several Rectangle shapes and few other grids.

It looks like this:

<Grid>
    <!-- WINDOW BACKGROUND -->
    <Rectangle Stroke="#FF214E80" RadiusX="3" RadiusY="3" ClipToBounds="True">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF193C6C" Offset="0"/>
                <GradientStop Color="#FF2A65A4" Offset="1"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <!-- // WINDOW BACKGROUND -->

    <!-- HEADER HIGHLIGHT2 -->
    <Rectangle HorizontalAlignment="Stretch" Margin="2,2,2,0" VerticalAlignment="Top" Height="62" RadiusX="2" RadiusY="2">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#00193C6C" Offset="1"/>
                <GradientStop Color="#4C96ABC3" Offset="0"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <!-- // HEADER HIGHLIGHT2 -->
<Grid>
 ....
</Grid>

These rectangle shapes are used in other window dialogs as well.

My questions are:

How would it be possible to store these recatangles inside WPF resource dictionary?

How would I be able to reference them?

A: 

You can create a style in your resource dictionary for these items with setters for each property--one included below.

<Style TargetType="{x:Type Rectangle}" x:Key="WindowBackground">
  <Setter Property="Stroke" Value="#FF214E80"/>
</Style>

Then in your window you can reference the style as such..

<Rectangle Style="{StaticResource WindowBackground}"/>
Jeff Wain
Thank You for Your answer, but that would will have to create separate style for each rectangle.
Daniil Harik
Do you have your resources declared at the application level or on a per-project basis? If you're re-using your references you should have them at the app level since your memory usage will increase each time you declare them at a per-project basis. And yes, you will need 2 styles regardless.
Jeff Wain
A: 

Actually the solution was quite simple WPF UserControl did the trick for me

Daniil Harik