Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3360116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:57:15+00:00 2026-05-18T02:57:15+00:00

I want to set an image’s source according to its DataContext in a ChildWindow

  • 0

I want to set an image’s source according to its DataContext in a ChildWindow. Here is the XAML file:

<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}">
  ...
  <Image x:Name="DialogIcon"></Image>
  ...
</controls:ChildWindow>

It’s working fine if I override the Show method of the ChildWindow and set the image’s source:

public new void Show()
{
    DialogIcon.Source = new BitmapImage(new Uri(@"/Images/DialogWindow/Confirm.png", UriKind.Relative));
    base.Show();
}

But it looks ugly and it’s not the “silverlight way”, so I decide to change:

<Image x:Name="DialogIcon" Source="{Binding DialogIconType, Converter={StaticResource DialogIconConverter}}"></Image>

You see I have a DialogIconConverter registered to bind the source from the DataContext.

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));
    }
    ...
 }

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?

EDIT: DialogIconType is an enum, and also it’s a property of DialogContext. An instance of DialogContext will be assigned to DataContext property of the DialogWindow.

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:57:15+00:00Added an answer on May 18, 2026 at 2:57 am

    might be silly, but did you make sure that your converter is referenced properly in your xaml file ?

    otherwise, I suggest trying this syntax as path for your URI (with images setup as resources):

    return new BitmapImage(new Uri("pack://application:,,,/Images/DialogWindow/Confirm.png", UriKind.Relative));
    

    EDIT :

    ok, I think I’ve got it :
    look into your output window, you will probably see some error 40 binding … blablabla…

    My guess is that the converter is right, but the source of the binding isn’t, so basically the converter is not even used.

    The reason is that your DialogIconType is not a dependency property, so it cannot be bound to.

    in other words, this :

    public DialogIconType IconType { get; set; }
    

    should become this :

    public static DependencyProperty IconTypeProperty = DependencyProperty.Register("IconType", typeof(DialogIconType), typeof(DialogContext));
    public DialogIconType IconType
    {
        get { return (DialogIconType)(GetValue(IconTypeProperty)); }
        set { SetValue(IconTypeProperty , value); }
    }
    

    plus, in your Xaml, you should Bind to “IconType”, and not “DialogIconType” (which is a type and not a property)

    (this might even be the sole issue, as I’m not sure if a dependencyProperty Is actually realy needed here, now that I think of it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create one application used form class now its very simple,I want set background
I want to set an image as my background at runtime, so I created
I want to set background image to right and top of my span because
I want to set a background image to different divs, but my problems are:
I want to set the thumb image of a slider for a normal state,
I want to set the Expires header for all image/* and text/css . I'm
i want have an image and i want to set it as a background
I want to place links over a background image (set in CSS) and I
I have an image with height 173px and width 157px .I want to set
I want to use a set of 2 image layers as a background in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.