There is another thread, the window controls should be changed. Namely, Image and its property ToolTip. WPF Code:

<Image x:Name="IconState" HorizontalAlignment="Left" Height="25" Margin="4,10,0,0" VerticalAlignment="Top" Width="25" Source="Images/ExImage.png" Grid.RowSpan="2" ToolTip="Some Tip"/> 

C # code:

 FFM.Dispatcher.Invoke(new ThreadStart(delegate {; FFM.IconState.ToolTip = "Example tip 2"; })); //Обновляем ToolTip BitmapImage ImageP = new BitmapImage(new Uri("/Images/ExImage2.png", UriKind.Relative)); //Объявляем изображение FFM.Dispatcher.Invoke(new ThreadStart(delegate {; FFM.IconState.Source = ImageP; })); //Меняем изображение 

On the last line, we have an exception: System.InvalidOperationException: "Вызывающий поток не может получить доступ к данному объекту, так как владельцем этого объекта является другой поток."

Why it happens? After all, Dispatcher.Invoke does not allow the execution of the code to go further until the response from the dispatcher comes, that is, the idea should not exist.

    1 answer 1

    The problem is that you create a BitmapImage not in a UI stream. It is considered to belong to the background thread (this is the very “other thread” from your error message), and cannot be used in other threads.

    There are two possible ways out of this situation:

    1. Create it in a UI stream using the same Dispatcher .
    2. BitmapImage your BitmapImage from the BitmapImage that created it with ImageP.Freeze() . In this case, however, you can no longer change the properties of this BitmapImage object (but with good chances you don’t need to).

    By the way, you can call the code more simply syntactically:

     FFM.Dispatcher.Invoke(() => { FFM.IconState.ToolTip = "Example tip 2"; }); 

    or even

     FFM.Dispatcher.Invoke(() => FFM.IconState.ToolTip = "Example tip 2"); 
    • You can find out how to contact you, except for StackOverflow, because there are a couple of questions that are not very useful to ask here, but want to. PS If you have such a desire, of course. - SKProCH
    • @SKProCH: Sorry, I'm usually busy with work, so it's better on the site. For example, I am in C # chat . - VladD