Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Change ImageSource property of ImageBrush

 
 
Old 09-14-2006   #1 (permalink)
=?Utf-8?B?UmFnaGF2ZW5kcmE=?=


 
 

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

My System SpecsSystem Spec
Old 09-14-2006   #2 (permalink)
Adam Smith [MS]


 
 

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



My System SpecsSystem Spec
Old 09-15-2006   #3 (permalink)
=?Utf-8?B?UmFnaGF2ZW5kcmE=?=


 
 

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

>
>
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Struggling to change property at end of pipeline PowerShell
How can you change the comments property of a jpg VB Script


Vista Forums 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 Ltd

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