Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic image source binding in silverlight
    primarykey
    data
    text
    <p>I want to set an image's source according to its <code>DataContext</code> in a <code>ChildWindow</code>. Here is the XAML file:</p> <pre><code>&lt;controls:ChildWindow x:Class="CEM.Controls.DialogWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Title="{Binding Title}"&gt; ... &lt;Image x:Name="DialogIcon"&gt;&lt;/Image&gt; ... &lt;/controls:ChildWindow&gt; </code></pre> <p>It's working fine if I override the <code>Show</code> method of the <code>ChildWindow</code> and set the image's source:</p> <pre><code>public new void Show() { DialogIcon.Source = new BitmapImage(new Uri(@"/Images/DialogWindow/Confirm.png", UriKind.Relative)); base.Show(); } </code></pre> <p>But it looks ugly and it's not the "silverlight way", so I decide to change:</p> <pre><code>&lt;Image x:Name="DialogIcon" Source="{Binding DialogIconType, Converter={StaticResource DialogIconConverter}}"&gt;&lt;/Image&gt; </code></pre> <p>You see I have a <code>DialogIconConverter</code> registered to bind the source from the <code>DataContext</code>.</p> <pre><code>public class DialogIconConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { //currently it's an hard-coded path return new BitmapImage(new Uri(@"/Images/DialogWindow/Confirm.png", UriKind.Relative)); } ... } </code></pre> <p>But it's not working now, I have several other converters in this control which are working fine. Only this one is not working. Can you help to find where the problem is?</p> <p>EDIT: <code>DialogIconType</code> is an enum, and also it's a property of <code>DialogContext</code>. An instance of <code>DialogContext</code> will be assigned to <code>DataContext</code> property of the <code>DialogWindow</code>.</p> <pre><code>public enum DialogIconType { Confirm, Alert, Error } public class DialogContext { public string Title { get; set; } public string Content { get; set; } public DialogButtons Buttons { get; set; } public DialogIconType IconType { get; set; } } internal DialogWindow(DialogContext context) { InitializeComponent(); this.DataContext = context; } </code></pre>
    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.
 

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