Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Change ImageSource property of ImageBrush

Closed Thread
 
Thread Tools Display Modes
Old 09-14-2006   #1 (permalink)
=?Utf-8?B?UmFnaGF2ZW5kcmE=?=
Guest


 

Change ImageSource property of ImageBrush

Hi,
I use an ImageBrush object within a Rectangle defined as below,
<Rectangle ..........>
<ImageBrush x:Name="imgBrush" ImageSource="D:\Azul.jpg"/>
</Rectangle>

On the occurence of an event, I want to change the ImageSource of ImageBrush
to some other value, say, "D:\\Blue Hills.jpg".
How do I do this from code-behind in C# ?

I cannot seem to do this - imgBrush.ImageSource = "D:\\Blue Hills.jpg";
Throws an error - 'Cannot implicitly convert from string to
System.Windows.Media.ImageSource'.

Please help me.
I am new to both C# and .Net 3.0

Thanks,
Raghavendra
Old 09-14-2006   #2 (permalink)
Adam Smith [MS]
Guest


 

Re: Change ImageSource property of ImageBrush

The type of ImageSource is "ImageSource", not string. When parsing the
XAML, we convert your strings to the actual types of the properties via
TypeConverters. From code, you'll want to create an instance of a type
which derives from ImageSource and assign this to the ImageBrush.ImageSource
property. To create a bitmap, you'll likely want to create a BitmapImage,
like so:

//Create source
BitmapImage bi = new BitmapImage();
//BitmapImage.UriSource must be in a BeginInit/EndInit block
bi.BeginInit();
bi.UriSource = new
Uri(@"pack://application:,,/sampleImages/cherries_larger.jpg");
bi.EndInit();

(
http://windowssdk.msdn.microsoft.com...tmapimage.aspx )

-Adam Smith [MS]

"Raghavendra" <Raghavendra@discussions.microsoft.com> wrote in message
news:ABBD47BA-52A1-4F51-B1F7-1B97A76952F1@microsoft.com...
> Hi,
> I use an ImageBrush object within a Rectangle defined as below,
> <Rectangle ..........>
> <ImageBrush x:Name="imgBrush" ImageSource="D:\Azul.jpg"/>
> </Rectangle>
>
> On the occurence of an event, I want to change the ImageSource of
> ImageBrush
> to some other value, say, "D:\\Blue Hills.jpg".
> How do I do this from code-behind in C# ?
>
> I cannot seem to do this - imgBrush.ImageSource = "D:\\Blue Hills.jpg";
> Throws an error - 'Cannot implicitly convert from string to
> System.Windows.Media.ImageSource'.
>
> Please help me.
> I am new to both C# and .Net 3.0
>
> Thanks,
> Raghavendra



Old 09-15-2006   #3 (permalink)
=?Utf-8?B?UmFnaGF2ZW5kcmE=?=
Guest


 

Re: Change ImageSource property of ImageBrush

Thanks a lot Adam. I am able to do that now.
Thanks.

"Adam Smith [MS]" wrote:

> The type of ImageSource is "ImageSource", not string. When parsing the
> XAML, we convert your strings to the actual types of the properties via
> TypeConverters. From code, you'll want to create an instance of a type
> which derives from ImageSource and assign this to the ImageBrush.ImageSource
> property. To create a bitmap, you'll likely want to create a BitmapImage,
> like so:
>
> //Create source
> BitmapImage bi = new BitmapImage();
> //BitmapImage.UriSource must be in a BeginInit/EndInit block
> bi.BeginInit();
> bi.UriSource = new
> Uri(@"pack://application:,,/sampleImages/cherries_larger.jpg");
> bi.EndInit();
>
> (
> http://windowssdk.msdn.microsoft.com...tmapimage.aspx )
>
> -Adam Smith [MS]
>
> "Raghavendra" <Raghavendra@discussions.microsoft.com> wrote in message
> news:ABBD47BA-52A1-4F51-B1F7-1B97A76952F1@microsoft.com...
> > Hi,
> > I use an ImageBrush object within a Rectangle defined as below,
> > <Rectangle ..........>
> > <ImageBrush x:Name="imgBrush" ImageSource="D:\Azul.jpg"/>
> > </Rectangle>
> >
> > On the occurence of an event, I want to change the ImageSource of
> > ImageBrush
> > to some other value, say, "D:\\Blue Hills.jpg".
> > How do I do this from code-behind in C# ?
> >
> > I cannot seem to do this - imgBrush.ImageSource = "D:\\Blue Hills.jpg";
> > Throws an error - 'Cannot implicitly convert from string to
> > System.Windows.Media.ImageSource'.
> >
> > Please help me.
> > I am new to both C# and .Net 3.0
> >
> > Thanks,
> > Raghavendra

>
>
>

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread-safety: Change property of items in arraylist versus removingitems from the arraylist Curious .NET General 2 4 Weeks Ago 06:36 AM
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 azerty Avalon 0 04-14-2008 06:14 AM
ImageSource to byte[] Fabrizio Di Santo Avalon 4 01-11-2007 10:46 AM
How to add handler or listen to a change of dependency property HolaMan Avalon 9 05-04-2006 11:17 PM
ImageSource Roman Avalon 4 04-22-2006 06:19 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50