I'm just doing a basic practice project that envolves a street light and the light/image changes color at the push of a button. at design time I can see all three of my images clearly but at runtime none of them will show up. I searched the hell out of google and I followed about three different examples but nothing will work.

this is what I have in my xaml code so far

<Window x:Class="stopLightDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="517" Margin="6,0,-6,0">
        <Button x:Name="btnGreen" Content="Green" Margin="310,30,50,0" VerticalAlignment="Top" Height="24" Click="btnGreen_Click" />
        <Button x:Name="btnYellow" Content="Yellow" Margin="310,71,50,0" VerticalAlignment="Top" Height="24" Click="btnYellow_Click"/>
        <Button x:Name="btnRed" Content="Red" HorizontalAlignment="Left" Margin="310,112,0,0" VerticalAlignment="Top" Width="157" Height="24" Click="btnRed_Click"/>
        <Button x:Name="btnClose" Content="Close" HorizontalAlignment="Left" Margin="310,256,0,0" VerticalAlignment="Top" Width="157" Height="29" Click="btnClose_Click" />

        <Image HorizontalAlignment="Left" Height="299" Margin="25,10,0,0" VerticalAlignment="Top" Width="227" Source="images/Stop.png" Name="imgStop"/>
        <Image HorizontalAlignment="Left" Height="299" Margin="25,10,0,0" VerticalAlignment="Top" Width="227" Source="images/Caution.png" Name="imgCaution"/>
// I tried somthing different here with the green light*********************************************************************
        <Image HorizontalAlignment="Left" Height="299" Margin="25,10,0,0" VerticalAlignment="Top" Width="227">
            <Image.Source>
                <BitmapImage DecodePixelWidth="227" DecodePixelHeight="299" UriSource="images/Go.png"/>
            </Image.Source>
            </Image>
    </Grid>
</Window>

now heres my C# code
I use the whole bitmap aproach here!!!

using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace stopLightDemo
{

    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnGreen_Click(object sender, RoutedEventArgs e)
        {
        Image myImage = new Image();
        myImage.Width = 227;
        BitmapImage myBitmapImage = new BitmapImage();
        myBitmapImage.BeginInit();
        myBitmapImage.UriSource = new Uri(@"G:\Users\Jason\Documents\C# Projects\WPF\stopLightDemo\stopLightDemo\images\Go.png");
        myBitmapImage.DecodePixelWidth = 227;
        myBitmapImage.EndInit();
        myImage.Source = myBitmapImage;
        }

        private void btnYellow_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnRed_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}

what could I be possibly be doing wrong????

Thank You!!!

Okay I am going to take a shot in the dark. I haven't done a lot with images, but when the GUI doesn't display an image like it should I do a Update().

It can sometimes force the system to update. You could try

myImage.Update(); 

Let me know if this works (it doesn't hurt to try), sorry I can't help much more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.