![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 |
| | #3 (permalink) |
| 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 > > > |
| |
| |
![]() |
| 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 |