tags:

views:

414

answers:

2

I'm learning WPF on my own and I can't seem to find a way to make this work.

Here's my code:

<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="600" Width="800" >
<DockPanel>
    <Menu DockPanel.Dock="Right"
          Height="30"              
          VerticalAlignment="Top"
          Background="#2E404B"
          BorderThickness="2.6">
        <Menu.BitmapEffect>
            <DropShadowBitmapEffect Direction="270" ShadowDepth="3" Color="#2B3841"/>
        </Menu.BitmapEffect>                          
    </Menu>
</DockPanel>

How can I make a .BackgroundImage thing appear? :D

+1  A: 

To set a background Image to control you have to add ImageBrush markup

<MenuItem.Background>
    <ImageBrush ImageSource="path/to/image.png" />
</MenuItem.Background>

If you want to make a background for the whole window you have to change MenuItem by Window

Zied
+3  A: 

Or, perhaps, you could use Visual Brush:

<Window
    x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" Height="600" Width="800">
  <Window.Background>
    <VisualBrush TileMode="Tile" Viewport="0,0,0.5,0.5">
      <VisualBrush.Visual>
        <Image Source="image.png"></Image>
      </VisualBrush.Visual>
    </VisualBrush>
  </Window.Background>
</Window>
kfrej
Would you please explain what the four digits in ViewPort mean? I've played with them, but I can't seem to figure out what the do concisely.
Sergio Tapia
Viewport property sets the position and dimensions of the base tile. Have a look at examples here: http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.viewport.aspxBasically, "0,0,0.5,0.5" means that the base tile will take space from point (0,0) to (0.5,0.5) - i.e. from the upper left corner of the output area to centre. (1,1) is the lower right corner.You should make use of MSDN Library. It's really useful. All the answers are there.
kfrej