Replies: 2 comments 1 reply
-
Layout doesn't happen immediately when you change things in your view model. There might be no ScrollViewer materialized yet, controls might still have no size, etc. Scheduling your callback via dispatcher makes sure that UI is ready for interactions like scrolling |
Beta Was this translation helpful? Give feedback.
0 replies
-
Tip you can also use Dispatcher.Post if you don't need to wait for the result. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
in my project I am trying to follow the MVVM pattern. It seems I am lacking some understanding of asynchronous operation, especially about the handling of menu items and buttons.
in myview.axaml I am typically using the following code snippet
with myview.axaml.cs
and in myviewviewmodel.cs
How to apply
ScrollIntoView
?Calling
DataGrid.ScrollIntoView(ViewModel.SelectedItem, null)
withoutDispatcher
is not working properly. Sometimes it is not scrolled. But why is it not working? The call is within the UI thread.dito with calling
Dispatcher.UIThread.Invoke(() => DataGrid.ScrollIntoView(ViewModel.SelectedItem, null));}
Calling
InvokeAsync
is working, the last entry is scrolled into view.Is it better/necessary to do
await Dispatcher.InvokeAsync()
? I think so. Then the event handlerOnClick
would have to beasync
. But if so, why is it working withoutawait
for 'InvokeAsync()' if `Invoke()' does not?Joachim
-- EDIT: --
What is the best dispatcher priority in that case?
Beta Was this translation helpful? Give feedback.
All reactions