.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Value Converter Without Binding On Image Source

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :WPF

I need to get the path of an image through a value converter. However I can't find any examples of using a value converter without binding.

I would be looking to do something along these lines:

<Image source="{Value=Image1, Converter={ImageConverter}}" />

The image converter will then go check an image folder and return the correct file path.

View Complete Post

More Related Resource Links

Binding byte[] to image control in navigation application leaks

Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

Menu Data Binding from XML source

Hi , I have the following complex XML structure. I need to bind the values to menu via Binding from the XML source <Editions>      <Edition Name="A">            <Products>                  <Product Name="1">                        <Platforms>                              <Platform Name="11">                                    <A1 Name="A"/>                                    <B1 Name="B"/>                                    <C1 Name="C"/>  

TextBox shows binding source text when window load, so why not with the ComboBox?

How can I get a ComboBox to show the binding source value when my window opens?  I have been searching all day for a solution to this, but cannot find anything.  So I have created a sample project to demonstrate my problem.  Below is a Vehicle class, very simple, two members Category and Make.  Category is an enumeration, Make is a string. namespace ComboExample { public class Vehicle { // Constants and enumerations public enum eCategory { Road, Air, Sea } // Attributes public eCategory Category { get; set; } public String Make { get; set; } // Construction public Vehicle(eCategory Category, String strMake) { this.Category = Category; this.Make = strMake; } } } Here is the C# for the MainWindow.  A new Vehicle object is created as a member.  In the constructor I set a data-provider in the XAML to this Vehicle object.  There is a button event for showing the values of the controls and objects so I can check the binding. namespace ComboExample { // Interaction logic for MainWindow.xaml public partial class MainWindow : Window { // Attributes Vehicle m_Car = new Vehicle(Vehicle.eCategory.Road, "BMW"); // Construction public MainWindow() { InitializeComponent(); // link data-p

Failed to set image source with string resource

User can set image source property like this: <Image Source="pack://application:,,,/MyResource;component/Images/1.ico" /> I think the source string is a little bit longer, so I want to make it as string resource: <sys:String x:Key="StringSourceKey">pack://application:,,,/MyResource;component/Images/1.ico</sys:String> After define the string resource, I use it to set image source, like this: <Image Source="{StaticResource StringSourceKey}" /> But, this time, it failed. It doesn't work. I think it is a contert error. Anybody know what's wrong?  Or any method to make the resource uri path shorter? Thanks.

How convert bitmap to Image.source ?

I hold some bitmap object in the memory  ( simple System.Drawing.Bitmap ). I want to make some wpf image control to show this bitmap. I dont want to save the bitmap to the disk and then load it as URI to the wpf image control So, How can i do this simple action ?   Thanks.

Binding the sharepoint treeview to the quick launch data source

Is there any way i can bind the sharepoint treeview navigation to the same datasource as the quick launch bar? I'm trying to create a consistent navigation structure within a 4-site deep structure so the quick launch bar is rather clunky to use, but the treeview picks up on document libraries i don't want it to (i only want it to show subsites and pages).

linq to sql varbinary assign to image source

Hi All, can you please tell me why this doesnt work:   <Grid> <Image Source="{Binding Path=currentUser.userStatus.icon.bm}" Width="89" Height="90" Margin="309,140,270,99" Name="im" /> </Grid>   where as if I assign the image source via the code behind it does? im.Source = currentUser.userStatus.icon.bm; The currentUser.userStatus.icon.bm object is a BitmapImage type generated from a database varbinary field using linq to sql partial methods like this:   public partial class icon { public BitmapImage bm = new BitmapImage(); public System.Drawing.Icon ic; public System.Drawing.Image img; partial void OnLoaded() { byte[] data = (byte[])this.imageBinary.ToArray(); MemoryStream strm = new MemoryStream(); strm.Write(data, 0, data.Length); strm.Position = 0; img = System.Drawing.Image.FromStream(strm); System.Drawing.Bitmap b = (System.Drawing.Bitmap)img; ic = System.Drawing.Icon.FromHandle(b.GetHicon()); //string imagePath = "Icons/go-down-8.ico"; //System.Drawing.Image img = System.Drawing.Image.FromFile(imagePath); //BitmapImage bi = new BitmapImage(); bm.BeginInit(); bm.DecodePixelWidth = 128; MemoryStream ms = new MemoryStream(); if (this.ext

Looking for a way to use a DynamicResource as the source of a binding expression


This is what I've found:

- The DynamicResource MarkupExtension returns a ResourceReferenceExpression which, when assigned to a dependency property of a dependency object that is part of the visual or logical tree, will be invalidated and updated when a resource with the matching key is added to the tree.

- A binding expressions Source property is not a dependency property

- A binding expression is not part of the visual or logical tree when used as a markup extension (or even assigned via property syntax)


My goal is to have something like the following:
<TextBlock Text="{MyBinding Key=SomeResource, Path=Some.Resource.Path}" />

The resource wouldn't be assigned until after the XAML is loaded.

Wouldn't it be reasonable to have my custom markup extension return a derived type of ResourceReferenceExpression, which could do the dirty work. I see a few possibilities, perhaps even something with a custom value converter that could be leveraged to create a binding expression to the value that gets returned when the expression is evaluated?

Any plans to allow this kind of extensibility (or if anyone knows if deferred binding to property paths will be added)?

Can't seem to get into or extend the classes that make this stuff tick. Any ideas? (yeah.. I'm probably jumping all over the place,

Change image in gridview after binding


I have a need to change the image (bound) in a gridview after it has been databound.  Basically i need to assign a photo to a record and I want to change the image url for that row.  I can change the text in any of the cells of the row but I can't seem to find property for the imageurl.

This is what I do to change the text(cell 5).

int index = int.Parse(Session["NSI"].ToString());

GridViewRow row1 = GridView1.Rows[index];
row1.Cells[5].Text = "just some text";

But now I need to change the image url for cell 0

something along the lines of ...

row1.Cells[0].ImageUrl = "~images\photos\12345.jpg";

How do I get to that property?

Thank you.

'No information was found about this pixel format error' on image binding

I've read all the posts I could find on this error but I'm still stumped.

I have a user control with a dependency property named Image.

In the user control I have a stack panel that contains an image and I set the binding in the xaml

<Image HorizontalAlignment="Center" Margin="3,0,0,0" Width="85" Height="75" Source="{Binding ElementName=UserControl, Path=Image}"/>

In a code behind I try to set the image for an instance of this control named WeatherNB

                BitmapImage bi1 = new BitmapImage();
                bi1.UriSource = new Uri(currentImage, UriKind.Relative);
                this.WeatherNB.Image = bi1;

but I get the following error

Unhandled Exception: System.NotSupportedException: No information was found about this pixel format.
   at System.Windows.Media.PixelFormat.CreatePixel

Binding a DVDropDown control to a XML data source


I'm having a heck of time figuring how to get my DVDropDown control to display items from the SoapDataSource (SOAP web service) or XmlDataSource (REST).


If I create a data view for the same data sources, I can see the data just fine, but when I go to Data Fields dialog, I can select the data source in the dropdown but in all cases, the two other dropdown to pick the value and display text are blank and there's nothing for me to select though I know there should be columns available for selection.


I've also tried manually coding those parameters, accounting for the possibility that I may need fully qualified XPath to get to the column itself but that causes an error.


What could I be missing?



Set Image Source to DIB in Memory?


Hello all.

I have a piece of hardware saving image data to memory which I would like to retrieve and set as the source to an Image element.  I am able to ask the hardware for a DIB handle to the image -- the return value is documented as "a long, which should be cast to a HBITMAP".  How can I do this in WPF?

I'm currently reading up on BitmapSource.Create(), which takes an IntPtr to memory, but I'm not sure it is expecting a DIB or not.  Also, the function asks for "stride" which I am unfamiliar with computing.  This appears to be the most promising though, since I can set it straight to an Image.Source parameter.

The hardware I have also has a function to grab a LPPICTUREDISP handle, which is documented as being compatible with the "Picture Object" of Visual Basic and C++.  From my reading so far it doesn't sound like this is something that is better suited for my needs, but I'm not sure.

Thanks for any help

How to change wpf image source on runtime ?


I get new bitmap from some other component ( dont have any control on the other component ) every 5 seconds and i need to update my wpf image control with the new bitmap ( every 5 seconds ... ).


[ i cant save the bitmap to the disk and then load it as file ]

I cant find any way to update this wpf image control in run-time.

How can i do it ?


Can't update image.source at runtime ( ??? )

I change wpf image.source dynamically during runtime.
Its seen everything is find - the image is not empty ( i saving it to my disk )...
but on the "image.source = ... " i dont see any image on the Image controler.
Actually - i dont see any image on the image controler.

I check if the Image controler can have some hard code image ( not change on runtime ) and its look fine also. Just update the image.source is not update the right image on the runtime.

The code is simple 3 line ... function name that get argument of BitmapImage and then call => image.source = BitmapImage - that it ===> image is the x:Name of the Image object on the xaml.

Any suggestion? what to check ... ? what is wrong ?


Validate Binding that is part of a BindingGroup on LostFocus without updating source


By default, when you tab out of a TextBox whose Text property is data bound, the value is pushed to the data source.  Data validation occurs as part of this process.

When you create a BindingGroup and the Binding becomes part of this BindingGroup, the value is no longer pushed to the data source when the TextBox loses focus.  This is what I want.  However, the data validation no longer occurs.  This is not what I want.

How do I validate a binding that is part of a BindingGroup on LostFocus without updating the source?  I want my users to have immediate feedback of data entry errors but I want to retain control over when data is pushed to the data source.

It would be great if this could be implemented as a style in a Theme.xaml file or any other solution that would not require hooking up to each and every LostFocus event handler in my application.

Binding Source and DataGridView not talking

I have on a form a bindingsource, a dataviewgrid, a bindingsourcenavigator, a tableadaptor and a few textboxes linked to the


I need to be able to change the data using a query.

I have the following code which is generated when i select inactive or active for example:

Dim connString As

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend