2

I'd like to create my custom error/exception dialog with the standard Windows "Error icon".

I followed the advice from this question and it works.

However I'm currently creating an instance property I bind to just like to any property:

class ErrorWindowViewModel
{
    private readonly ImageSource _errorImage;

    public ImageSource ErrorImage { get { return _errorImage; } }

    public ErrorWindowViewModel()
    {
        _errorImage = Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Error.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    }
}

What I'd like to do is to have a static field defined in my ErrorWindow class:

partial class ErrorWindow : Window
    {
        private readonly static ImageSource ErrorImage = 
            Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Error.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    }

I can't force my XAML to reference that field.

<Image Source="what_to_put_here_to_make_it_work" />

I'm using WPF 4.5.

1 Answer 1

3

You would have to create a static property

private static readonly ImageSource errorImage =
    Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Error.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

public static ImageSource ErrorImage
{
    get { return errorImage; }
}

and bind like this:

<Image Source="{Binding Source={x:Static local:ErrorWindow.ErrorImage}}"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.