Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't want to preload the image, you would have to create a dependancy property on Main Window. You would also have to use <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx" rel="nofollow noreferrer">WPF Pack URIs</a>. The XAML and codebehind files are given below:</p> <p>XAML : </p> <pre><code>&lt;Window x:Class="TestWPFApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestWPFApp" Title="MainWindow" Height="550" Width="725"&gt; &lt;Grid x:Name="MainGrid"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Orientation="Horizontal" Grid.Row="0"&gt; &lt;Label Content="Select Image" Width="100" Height="30" Margin="10,10,100,10"&gt;&lt;/Label&gt; &lt;ComboBox x:Name="cbImageSelect" Height="20" Width="400" SelectionChanged="ComboBox_SelectionChanged" /&gt; &lt;/StackPanel&gt; &lt;ContentPresenter x:Name="contentPresenter" Width="250" Height="250" Grid.Row="1" &gt; &lt;ContentPresenter.Content&gt; &lt;Image Source="{Binding ImageUri}" Width="220" Height="220"&gt; &lt;/Image&gt; &lt;/ContentPresenter.Content&gt; &lt;/ContentPresenter&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>XAML.cs</p> <pre><code>using System.Collections.Generic; using System.Windows; using System.Windows.Controls; namespace TestWPFApp { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; cbImageSelect.ItemsSource = new List&lt;string&gt;() { "test1.bmp", "test2.bmp" }; } public static readonly DependencyProperty ImageUriProperty = DependencyProperty.Register("ImageUri", typeof(string), typeof(MainWindow)); public string ImageUri { get { return (string)GetValue(ImageUriProperty); } set { SetValue(ImageUriProperty, value); } } private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ImageUri = "pack://application:,,,/" + ((sender as ComboBox).SelectedItem as string); } } } </code></pre> <p>Location of Images: test1.bmp and test2.bmp </p> <p><img src="https://i.stack.imgur.com/Za6FQ.png" alt="enter image description here"></p> <p>Properties of test1.bmp and test2.bmp<br> <img src="https://i.stack.imgur.com/Z172g.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/0NnV0.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload