Hi. I'm trying to asynchronously load data in a ViewModel when the ViewModel is created. Today I am using Catel in my application for MVVM functionality. If the Control is of type Catel.UserControl then an overridden method InitializeAsync is automatically called when the control loads allowing me to async load data.
However, I am migrating this application to use Telerik Docking. For docking to work I need the controls to be of type RadPane or RadDocumentPane. Making this modification breaks Catel's InitializeAsync functionality. So I'm left searching for the best way to asynchronously load data in aTelerik RadPane/RadDocumentPane.
I might have found a working solution, but I wanted to check if there's a better way to do this. The solution I found is to add an interaction trigger that fires an async command on the RadPanes 'Loaded' event. https://newbedev.com/calling-async-method-to-load-data-in-constructor-of-viewmodel-has-a-warning.
Edit: I should note that I'm using the Telerik DockingPrism7 sample.
Current XAML with Catel:
<catel:UserControl xmlns:catel="http://schemas.catelproject.com">
<Grid>
<telerik:RadGridView ItemsSource="{Binding Model}" />
</Grid>
</catel:UserControl>
ViewModel:
public class ObjectViewModel : Catel.MVVM.ViewModelBase
{
/// <summary>
/// Create model and get all tenants.
/// </summary>
/// <param name="tenantBL"></param>
/// <param name="security"></param>
public ObjectViewModel(BL bl) : base()
{
}
/// <summary>
/// Initialize control. Automatically called if Control is of type Catel.UserControl.
/// </summary>
/// <returns>Task</returns>
protected override async Task InitializeAsync()
{
await base.InitializeAsync();
await LoadDataFromBL();
}
/// <summary>
/// Load all data from the business logic.
/// </summary>
/// <returns>Task</returns>
private async Task LoadDataFromBL()
{
await DoSomething();
}
}