![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| 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 | |||