ネストされたusercontrolを持つ単純なアプリケーションがあります。ユーザーコントロールのフォーカスでCatelがフリーズする
MainWindow.xaml:命名規則の
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0">Test TextBox</TextBox>
<userControls:SuggestUserControl Grid.Row="1" Grid.Column="0"
DataContext="{Binding CitizenshipViewModel}" />
</Grid>
違反は、このユーザーコントロールのその後の再利用の理由です。その場合、私はApp.xaml.csでカスタムビューモデルを登録しています:
var viewLocator = ServiceLocator.Default.ResolveType<IViewModelLocator>();
viewLocator.Register(typeof(SuggestUserControl), typeof(CitizenshipSuggestViewModel));
CitizenshipSuggestViewModelは、いくつかの追加のロジック(私はテストresonにコメントしウィッヒ)、空のコンストラクタを持つ単純なクラスであり、基本クラスSuggestModule由来します:
public class SuggestModule<TEntity> : ViewModelBase
where TEntity : class, ISuggestable, new()
{
#region Private fields
private readonly IDataBaseService _dataBaseService;
#endregion
#region Default constructor
public SuggestModule(IDataBaseService dataBaseService)
{
Argument.IsNotNull(() => dataBaseService);
_dataBaseService = dataBaseService;
//Loading data from context
var collection = _dataBaseService.LoadObservableCollectionOf<TEntity>();
ItemsCollection = new ObservableCollection<TEntity>(collection);
ItemsCollection.Sort();
}
#endregion
...Some logic here...
}
MainWindowViewModel:
public class MainWindowViewModel : ViewModelBase
{
public MainWindowViewModel(Person person)
{
Argument.IsNotNull(()=>person);
Person = person;
}
[Model]
public Person Person
{
get => GetValue<Person>(PersonProperty);
set => SetValue(PersonProperty, value);
}
public static readonly PropertyData PersonProperty =
RegisterProperty<MainWindowViewModel, Person>(model => model.Person);
[ViewModelToModel("Person")]
public Citizenship Citizenship
{
get => GetValue<Citizenship>(CitizenshipProperty);
set => SetValue(CitizenshipProperty, value);
}
public static readonly PropertyData CitizenshipProperty =
RegisterProperty<MainWindowViewModel, Citizenship>(model => model.Citizenship);
public Citizenship Citizenship
{
get => GetValue<Citizenship>(CitizenshipProperty);
set => SetValue(CitizenshipProperty, value);
}
public static readonly PropertyData CitizenshipProperty =
RegisterProperty<MainWindowViewModel, Citizenship>(model => model.Citizenship);
public IViewModel CitizenshipViewModel
{
get => GetValue<IViewModel>(CitizenshipViewModelProperty);
set => SetValue(CitizenshipViewModelProperty, value);
}
public static readonly PropertyData CitizenshipViewModelProperty =
RegisterProperty<MainWindowViewModel, IViewModel>(model => model.CitizenshipViewModel);
protected override async Task InitializeAsync()
{
await base.InitializeAsync();
CitizenshipViewModel = this.GetTypeFactory().CreateInstance<CitizenshipSuggestViewModel>();
}
}
}
だから、SuggestModuleに完全にロードされたアプリケーション、特にItemsCollectionが既に満たされているときログの文脈からのデータは、この情報を得たと:
12:19:34:844 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model container to manage ViewToViewModel mappings
12:19:34:864 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initializing view model 'CitizenshipSuggestViewModel'
12:19:34:874 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model 'CitizenshipSuggestViewModel'
12:19:34:895 => [DEBUG] [Catel.MVVM.Views.ViewToViewModelMappingHelper] [1] Initialized view model container to manage ViewToViewModel mappings
しかし、私は、ネストされたユーザーコントロールの一部である第二のTextBox、上のフォーカスを取得した場合、今、私は約5 ... 6秒のフリーズを持っています。今回のログ情報:
12:23:21:212 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:21:387 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:21:809 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:21:901 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:016 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:063 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:221 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:235 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:585 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:654 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:22:703 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:23:019 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:23:319 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:23:431 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:24:105 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:24:566 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:24:644 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:25:803 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
12:23:26:115 => [DEBUG] [Catel.IoC.TypeFactory] [1] Cleared type constructor cache
どうすればこの問題を回避できますか? ありがとうございます!
はい、5.2 Catel、VS2017、debbugerなしの場合は同じ動作です... – ArieSLV
GitHubでrepro&ticketを作成できますか?それから私たちはそれを調べます! –
reproについてはhttps://github.com/Catel/Catel/issues/1140をご覧ください。 –