Skip to content
Loading
  • Mageshwaran R
    0
    Hi Manoj,
    Try this code,
     XAML:
    1. <StackPanel Orientation="Horizontal" Background="LightBlue" Height="40">    
    2.     <Label Margin="10,0,0,0" Height="23" Name="Label1">    
    3.         Current File:    
    4.     Label>    
    5.     <Label Margin="5,0,0,0" Height="25" Name="FileNameLabel" Width="300" />    
    6.     <Button Margin="5,0,0,0" Height="23" Name="BrowseButton" Width="75" Click="BrowseButton_Click">    
    7.         Browse    
    8.     Button>                    
    9.     StackPanel>    
    10. <StackPanel >    
    11.     <Image Name="ImageViewer1" Height="400" Width="400" />           
    12. StackPanel>    
     C#:
     
    1. private void BrowseButton_Click(object sender, RoutedEventArgs e)    
    2. {    
    3.     OpenFileDialog dlg = new OpenFileDialog();    
    4.     dlg.InitialDirectory = "c:\\";    
    5.     dlg.Filter = "Image files (*.jpg)|*.jpg|All Files (*.*)|*.*";    
    6.     dlg.RestoreDirectory = true;    
    7.     
    8.     if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)    
    9.     {    
    10.         string selectedFileName = dlg.FileName;    
    11.         FileNameLabel.Content = selectedFileName;    
    12.         BitmapImage bitmap = new BitmapImage();    
    13.         bitmap.BeginInit();    
    14.         bitmap.UriSource = new Uri(selectedFileName);    
    15.         bitmap.EndInit();    
    16.         ImageViewer1.Source = bitmap;    
    17.     }    
    18. }    
     
    0
  • 0
    Fixed issue thanks @rajnikant
    0