Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3843884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:00:07+00:00 2026-05-19T16:00:07+00:00

I am new to WPF so bear with me. I have set the background

  • 0

I am new to WPF so bear with me. I have set the background image of my window using an ImageBrush and now I want my window’s size to be exactly the size of the background image. The obvious solution to this is to simply set the width/height property manually with the pixel measurements of my background image, but this seems too naive. What is the best way to do this? Here is my XAML so far:

<Window x:Class="FruitFactory.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Fruit Factory" Height="576" WindowStyle="None" DataContext="{Binding}" ResizeMode="NoResize" Width="834">
    <Window.Background>
        <ImageBrush ImageSource="/FruitFactory;component/Graphics/FruitFactoryBackground.png"></ImageBrush>
    </Window.Background>
    <Window.Resources>
    </Window.Resources>
    <Grid>
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="52,27,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" />
    </Grid>
</Window>

I’m using Visual Studio 2010 and .NET 4.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:00:07+00:00Added an answer on May 19, 2026 at 4:00 pm

    You can bind Width and Height to PixelWidth and PixelHeight of the ImageSource for ImageBrush like this

    Update

    Realized my previous solution didn’t work because ImageSource didn’t have PixelWidth/PixelHeight since it wasn’t a BitmapImage. I had to use a BitmapImage resource instead but then the bindings didn’t work if I didn’t declare the Resource before the bindings (bug anyone?)

    <Window x:Class="WindowSameSizeAsBackground.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Fruit Factory"
            WindowStyle="None"
            DataContext="{Binding}"
            ResizeMode="NoResize">
        <Window.Resources>
            <BitmapImage x:Key="backgroundBrush"
                         UriSource="/FruitFactory;component/Graphics/FruitFactoryBackground.png"/>
        </Window.Resources>
        <Window.Width>
            <Binding Source="{StaticResource backgroundBrush}" Path="PixelWidth"/>
        </Window.Width>
        <Window.Height>
            <Binding Source="{StaticResource backgroundBrush}" Path="PixelHeight"/>
        </Window.Height>
        <Window.Background>
            <ImageBrush x:Name="imageBrush"
                        ImageSource="{StaticResource backgroundBrush}"></ImageBrush>
        </Window.Background>
        <Grid>
            <ComboBox Height="23" HorizontalAlignment="Left" Margin="52,27,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" />
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="258,179,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im new to wpf, so please bear with me i made a window for
I have created a new WPF Application using Visual Studio 2010 so I have
I am new to WPF/XAML so please bear with the noob question. I have
I'm very new to WPF, so please bear with me. Basically I have defined
I am creating a new WPF window that I want to be parented to
New to wpf and through a learning curve. I have a userControl with a
being new to WPF this is a complex problem for me. What i want
I am new to WPF. I have Created some user Controls with some basic
In a new WPF project (VS2010) i 'm using Unity 2 for the first
I created an add-in for PowerPoint and I want to add a new WPF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.