In a WPF application, you usually don't save images in Properties/Resources.resx and access them using the Properties.Resources class.
Instead of just adding image files to your visual studio project as regular files, perhaps in a folder called βImagesβ or the like. Then you set their Build Action to Resource , which will be executed in the Properties window. You get there, for example. by right-clicking the image file and select the Properties menu item. Note that the default value for Build Action must be Resource for image files anyway.
In order to access these image resources from code, you would then use the URI package . With the name of the "Images" folder and the image file named "LedGreen.png" above, creating such a URI will look like this:
var uri = new Uri("pack://application:,,,/Images/LedGreen.png");
So, you could declare that your property is of type Uri:
public Uri ImageUri { get; set; }
and install it like this:
ImageUri = resultInBinary.StartsWith("1") ? new Uri("pack://application:,,,/Images/LedGreen.png") : new Uri("pack://application:,,,/Images/LedRed.png");
Finally, your XAML should look like the one below, which relies on inline type conversions from Uri to ImageSource:
<Grid> <Image Width="10" Source="{Binding Path=ImageUri}" /> </Grid>
Clemens
source share