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

  • Home
  • SEARCH
  • 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 6672497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:30:55+00:00 2026-05-26T03:30:55+00:00

How do I know when XAML bindings are evaluated? -Is there a method /

  • 0

How do I know when XAML bindings are evaluated?

-Is there a method / event I can hook into?

-Is there a way I can force these bindings to evaluate?

I have the following XAML with 3 Images which each have their source a separate way:

<Window...>
<Window.Resources>
    <local:ImageSourceConverter x:Key="ImageSourceConverter" />
</Window.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Image x:Name="NonBindingImage" Grid.Column="0" Source="C:\Temp\logo.jpg" />
    <Image x:Name="XAMLBindingImage" Grid.Column="1" Source="{Binding Converter={StaticResource ImageSourceConverter}}" />
    <Image x:Name="CodeBehindBindingImage" Grid.Column="2" />
</Grid>
</Window>

Here is the converter referenced in the XAML:

public class ImageSourceConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        BitmapImage image = new BitmapImage();

        image.BeginInit();
        image.StreamSource = new FileStream(@"C:\Temp\logo.jpg", FileMode.Open, FileAccess.Read);
        image.EndInit();

        return image;
    }

And here is the window code:

...
public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();

        Binding binding = new Binding { Source = CodeBehindBindingImage, Converter = new ImageSourceConverter() };
        BindingOperations.SetBinding(CodeBehindBindingImage, Image.SourceProperty, binding);

        object xamlImageSource = XAMLBindingImage.Source; // This object will be null
        object codeBehindImageSource = CodeBehindBindingImage.Source; // This object will have a value

        // This pause allows WPF to evaluate XAMLBindingImage.Source and set its value
        MessageBox.Show("");
        object xamlImageSource2 = XAMLBindingImage.Source; // This object will now mysteriously have a value
    }
}
...

When the binding is set via code using the same converter, it evaluates immediately.

When the binding is set via XAML and a converter, it defers evaluation to some later time. I randomly threw a call to MessageBox.Show in the code, and it seemed to cause the XAML binding source to evaluate.

Is there any way I can address this?

  • 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-26T03:30:56+00:00Added an answer on May 26, 2026 at 3:30 am

    It will be evaluated on render. As MessageBox.Show() causes the UI thread to pump it will be evaluated before the messagebox is being shown.

    Try hooking into the Loaded method of the WPF Window and running what you need to do there.

    Edit: According to http://blogs.msdn.com/b/mikehillberg/archive/2006/09/19/loadedvsinitialized.aspx the loaded event should run after databinding. Failing that I would suggest looking at using the Dispatcher to queue up your code to run on the UI thread using Invoke

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

Sidebar

Related Questions

Does anyone know of any way to convert a simple gif to xaml? E.G.
I'd like to know how I can assign in XAML a dependency property of
As far as I know, everything done in XAML can be done in C#.
Does anyone know how I can do the equivalent XAML binding in code? <DataGrid
Is there a way to create a conditional binding in XAML? Example: <Window x:Name=Me
I know that in XAML you can change a ToolTip's binding with... <TextBlock Text=ABC
I know how to change the tooltip in the xaml side of things, but
What we ideally need is, to know how Microsoft handles XAML generated code (Those
I have the following structure in XAML: <Grid> <ItemsControl x:Name=Items ItemsSource={Binding Path=Pages} Grid.Row=0 Grid.Column=0>
Continuing from my last question , I'd like to know how can I bind

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.