Home » WPF

Setting an image as the background for a WPF user control?

I am trying to set a gif image as my background image in a WPF user control.

I select background in properties.

From the drop down box next to,


I click "Select image", find and select an image, intro.gif. V.S. gives it a path "/intro1.gif"

And the display box "Which I suspect should show a miniature of the background image selected", remains with the message "No Image Selected"

Repeated attempts to add the image simply increments the allocated path "/intro2.gif" etc..

And still "No Image Selected"

What am I doing wrong?



Is it possible to inherit a Windows User Control in WPF User Control. I mean a WinForms User control as a base class to a WPF User Control class (which would be of Xaml). Please let me know the steps or code snippet.

Thanks in advance.


Hi ,

I have user control, which get call on <id href>

i am setting some value on user control on prerender, so i can see value which selected 1st time, but when i re chnage value and again open pop up screen not see changed value.

even i can see from code behind my value setting correctly, and passing correctly on aspx page , but look like not reassing value


user contrl on aspx page:








below partial code 

user control:












<paramname="initParams"value="wxLat=<%=_wxLat %>,wxLng=<%=_wxLng %>,clientId=110001001,defZoom=7,multiLayerSupport=false,defLayer=<%=_defLayer %>,layerList=<%= _layerList%>"/>






<imgsrc="http://go.microsoft.com/fwlink/?LinkId=161376"alt="Get Microsoft Silverlight"style="border-style:none"/>







i am saving inkcanvas but it saves black image




rtb = newRenderTargetBitmap((int)signature.ActualWidth, (int)signature.ActualHeight, 0, 0, PixelFormats.Pbgra32);




BmpBitmapEncoder encoder = newBmpBitmapEncoder();






FileStream fs = File.Open(@"c:\test.bmp", FileMode.Create);




what's wrong?


I am trying to load a fax 4 tiff into the WPF imaging control.  On most of the tiffs I try, I get a negative image.  Using the tiffinfo utility, I don't see any differences, fill order, compression, etc. are the same.  I think it possibly the reverse of the fill order bug from the tiffencoder.  Does anybody have any ideas?

Here's my code:



Using oStream AsNewFileStream(_FileName, FileMode.Open, FileAccess.Read, FileShare.Read)

_Decoder =


BitmapDecoder.Create(oStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad)







_Pages = _Decoder.Frames.Count

_Page = 1

Viewer.Source = _Decoder.Frames(0)

Viewer.Stretch =




I have a list of high-resolution images obtained from a web server. I need to populate them in the surface SDK scatterview item. To show the images I am using Image control for each image.

Code Logic:
User has identity tags which being placed on the surface table will fetch a list of high-resolution images associated with that tag. The fetching of the images is run in background to avoid jamming the UI. The code to obtain JPEG images in the background is

public BitmapSource FetchImage(string URLlink)
    JpegBitmapDecoder decoder = null;
    BitmapSource bitmapSource = null;
      decoder = new JpegBitmapDecoder(new Uri(URLlink, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
    catch (Exception)
      decoder = new JpegBitmapDecoder(new Uri("pack://application:,,,/Resources/ImageNotFound.jpg", UriKind.RelativeOrAbsolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand);
      bitmapSource = decoder.Frames[0];
    return bitmapSource;

The images are downloaded from the server and displayed in the image control. However, there is severe performance hit and application just hangs when more than 10 images are loaded. For low-resolution images, i can load even 20-30 images without hanging or slowing down the application.

Since i read the default algorithm for image control is Fant, I tried chaning the rendering properties to HighQuality. Application still hangs, but any lower than this kills the whole idea of having a high-resolution image for display.

RenderOptions.SetBitmapScalingMode(mic.ItemImage, BitmapScalingMode.HighQuality);

Is there a better way of loading images. I was thinking of first saving images to hard-disk and then loading to image source. Would that be effective in improving performance because I was thinking when I am loading images directly from URL it would store it in memory which eventually runs out. By saving images first I might avoid this, but there might a chance .NET actually is doing the same thing of storing first in temp file and then loading.

I also tried changing the BitmapCacheOption to all the available options but it didn't improve anything.

Hi could anyone please tell me hoe to retrieve an image from a database and dynamically set it as the background of a canvas?

I'm trying to develop a customized image that will load as many defaults as possible.  I'm currently stumped with setting the background image that a user will see after an image is deployed. 

In the answer file under Windows Embedded Edition->Shell-Setup_x86 there is a setting for Themes->DesktopBackground.  According to the help text:  DesktopBackground specifies the path to a graphic file that is used for the desktop background.  This corresponds to the option: Picture Position: Fill in the Desktop Background page in the Control Panel. 

But, when I specify my path here, it does not get set.  My path is C:\MyCompany\BACKGROUNDDEFAULT.JPG.  The file is loaded though the $OEM$ Folders during install and the file is in the location specified after install.  I've tried setting this in passes P4 and P7, but no luck in either.

Can anyone shed light on what I'm doing wrong?



I want to have the background of my masterpage (the master page for all of my .aspx pages) have a sort of gradient.  I imagine the only way I can do that is with an image.  Or maybe even some other design, but I want to move away from the "solid color" background.

Is the easiest way to do this just to make an image and set that as the background?  What image size should I make it, because some users could possibly have the normal aspect ratio, or maybe a widescreen?  What should I make it like so that it looks good on all computers?

Thanks in advance. :) 



I have the most strange problem. I am trying to put an image to a <td> and a panel. The image is set to the Panel3 without problem but the image is not set to the <td> (NewImage1).

The path to the image is this and I have tried to hardcode this path also without success.


I have also tried to hardcode these pathes just to test without success:



(And to mention details here is that entering this page was caused by a Server.Transfer)

(The test.aspx and test.cs file is located in Folder1)

String topImagePath = Server.MapPath(Session["realPath2"].ToString() + "/Images/Image1.gif");
if (File.Exists(topImagePath) == true)
       Panel3.BackImageUrl = Session["realPath2"].ToString() + "/Images/Image1.gif";

       NewImage1.Attributes.Add("style", "background-image: url('" + Session["realPath2"].ToString() + "/Images/Image1.gif'); background-repeat: no-repeat; background-position: bottom left; height: 100%; width:100%");

<asp:Panel ID="Panel3" runat="server" Width="100%" Height="100%">

<table width="100%" id="buttonstable" runat="server">
                    <td runat="server" id="NewImage1" valign="bottom">


I cannot able to write to pdf from and set the background image in using itextsharp

hi all,

      I have developed windows application in VS2005 and i am using Ms Access database,

i stored image byte to ms access table,so i need to display this image to rdlc body background from Ms access database,i tried but i did get image..if anybody know please send some related code,because i am new in Windows application..

Thank You,



hi there,

I don't even know if it is posible but i want to change my background from my entire screen.

now i have my mainpage with a with and height of 600 to 800.

and the rest of my screen is white.

I already know that i can change this into black or yellow or whatever. but i want to place an image there.

see picture for more info

who can help me plz


Hi, I have a repeater control:

<asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource4">
                    <div >
                        <div style="background:url('<%# Eval("HomeSlideBgImage")%>') no-repeat top center" >
                        <%# Eval("HomeSlideBgImage")%>
                            <h2 id="welcome-heading">
                                <%#DataBinder.Eval(Container.DataItem, "HomeSlideHd")%>
                                <%#DataBinder.Eval(Container.DataItem, "HomeSlideSubHd")%>
                                <%#DataBinder.Eval(Container.DataItem, "HomeSlideText")%>

and I'm trying to print the value from the database  <%# Eval("HomeSlideBgImage")%>  into a style tag, but it is not returning any value.  I've tried various combinations of quotation marks.

Has anyone an idea what the problem is?





i registered an image in AssemblyInfo.cs like this:

[assembly: WebResource("MyControl.Icons.bold.png", "image/png")]


protected override void RenderContents(HtmlTextWriter output)
            output.Write("<p class='BoldButtons' onclick='event4()'>event4 </p>");

now i want to initialize that image in css file for background-image but it dose'nt work.

my css file is:

	background-image: url("MyControl.Icons/font_bold.png");
	border: 0px; 
	height: 21px; 
	width: 21px;

i also try with this :

background-image: url(<%=WebResource("MyControl.Icons.bold.png")%>);

but it dose'nt work.

please help me? 


 I have an image control that points to a jpg and I want to place a LoginView over the top of it.  How can I do that?  In another words, I want the jpg to be in the background and LoginView to be on top.





Is there a simply way to can change the Combobox drop down box's background without override whole combobox controltemplate?

the default combobox dropdown box background is white. we like to customize it. thx!



Hello I have the following wpf user control




<Grid Margin="5">








<RowDefinition Height="Auto"/>




<RowDefinition Height="*"/>








<TextBlock Name="txtbGeneralMsg" Foreground="Red" Grid.Row="0" Margin="5" Visibility="Collapsed" Text="" />




<TabControl HorizontalAlignment="Stretch" Name="tabControl1" VerticalAlignment="Stretch" Grid.Row="1">



insdied the tab Control I created several tabs each containing diverse controls (textboxes, buttons,etc...)

I'm using the following code:




visual = ((System.Windows.Controls.Panel)((userInterface as System.Windows.Controls.UserControl).Content)) ; //this is returning the main grid on the user control

//the follwoing is returning 2 (the textblock and the TabControl)

int ChildNumber= VisualTreeHelper.GetChildrenCount(control);

However :



for (int i = 0; i <= ChildNumber - 1; i++)


v = (


Visual)VisualTreeHelper.GetChild(control, i);



if (!(string.IsNullOrEmpty(((FrameworkElement)v).Name)) && ((FrameworkElement)v).Name.ToLower().Equals(name.ToLower()))




return (FrameworkElement)v;




if (VisualTreeHelper.GetChildrenCount(v) > 0) //when i=1 i.e. tabcontrol the number is not >0


M_GetControl(v, level + 1, name);


so how to access the buttons,texboxes etc....



Actually I'm looking for a way to find the control regardless of it's type

I mean isn't there a way like windows forms .FindControl(name, true)

the control that I will be looking for is either on a grid or inside a group box or inside a tab item

I'm looking for a generic way


Can anyone give me a sample code of adding a wpf user control ina windows form tab control.

Thanks in advance


 I have users connecting via terminals services at varying resolution / colour depths. If they are 256 colours they shouldn't get a desktop background / image, if they are higher than 256 then this should be applied.

 Environment is Windows Server 2003.

 Probably the wrong forum but not for lack of looking.

 Can anyone advise how to acheive the above? Ideally it would be run as part of the user login scripts to mount printers, network drive etc.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure