我以编程方式生成UI并在OnCreateView中进行绑定,并且在视图呈现在屏幕上之前会有明显的延迟。
我想知道是否可以延迟绑定,以便首先呈现控件并遵循绑定。请告知合适的功能。
原始代码:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
try
{
var fragmentView = base.OnCreateView(inflater, container, savedInstanceState);
var linearLayout = fragmentView.FindViewById<LinearLayout>(Resource.Id.linearLayout1);
BindingContext = new MvxAndroidBindingContext(Activity, new MvxSimpleLayoutInflater(inflater), ViewModel);
using (new MvxBindingContextStackRegistration<IMvxAndroidBindingContext>(
((IMvxAndroidBindingContext)BindingContext)))
{
var set = this.CreateBindingSet<ArticleFragment, ArticleFragmentViewModel>();
// Name field (one of many fields...
set.Bind(InflateEditableText(inflater, linearLayout, "Name"))
.For(v => v.Text)
.To(vm => vm.Item.Name)
.WithConversion("TrimmableString");
InflateAndBindValidationText(inflater, linearLayout, set, "Validator.Messages['Name']");
//
// Other fields follow... same pricinple as Name field
//
set.Apply();
}
return fragmentView;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
throw;
}
}
我还重构了代码以完成任务中的所有绑定,但是我得到了与某些“集合已更改”相关的间歇性错误(无法记住确切的错误)。我们的想法是通过ui线程完成布局,并在单独的线程上完成绑定,并在set.Apply()之前完成task.Wait()。它有效,但间歇性失败。
编辑:添加了跟踪。
FIRST RUN (2248 ms)
[0:]
mvx:Diagnostic: 16.89 Showing ViewModel ArticleDetailViewModel
[0:] mvx:Diagnostic: 16.89 Showing ViewModel ArticleDetailViewModel
06-04 16:17:35.244 I/mono-stdout(26420): mvx:Diagnostic: 16.89 Showing ViewModel ArticleDetailViewModel
06-04 16:17:35.729 I/Choreographer(26420): Skipped 60 frames! The application may be doing too much work on its main thread.
[0:]
mvx:Diagnostic: 17.70 Attempting to load new ViewModel from Intent with Extras
[0:] mvx:Diagnostic: 17.70 Attempting to load new ViewModel from Intent with Extras
06-04 16:17:36.059 I/mono-stdout(26420): mvx:Diagnostic: 17.70 Attempting to load new ViewModel from Intent with Extras
[0:]
mvx:Diagnostic: 17.72 Adding subscription 0556b442-e560-49d2-934d-74a9e703d43d for ArticleEditDoneMsg
[0:] mvx:Diagnostic: 17.72 Adding subscription 0556b442-e560-49d2-934d-74a9e703d43d for ArticleEditDoneMsg
06-04 16:17:36.069 I/mono-stdout(26420): mvx:Diagnostic: 17.72 Adding subscription 0556b442-e560-49d2-934d-74a9e703d43d for ArticleEditDoneMsg
[0:]
mvx:Diagnostic: 17.73 Nothing registered for messages of type MvxSubscriberChangeMessage
[0:] mvx:Diagnostic: 17.73 Nothing registered for messages of type MvxSubscriberChangeMessage
06-04 16:17:36.094 I/mono-stdout(26420): mvx:Diagnostic: 17.73 Nothing registered for messages of type MvxSubscriberChangeMessage
06-04 16:17:36.249 D/Mono (26420): Remapped public key token of retargetable assembly System from 7cec85d7bea7798e to b77a5c561934e089
06-04 16:17:36.249 D/Mono (26420): The request to load the retargetable assembly System v2.0.5.0 was remapped to System v2.0.0.0
06-04 16:17:36.299 D/Mono (26420): Unloading image System.dll [0x5cfefdc8].
06-04 16:17:36.309 D/Mono (26420): Image addref System[0x5d017280] -> System.dll[0x59d2ab60]: 16
06-04 16:17:36.309 D/Mono (26420): Assembly Ref addref FluentValidation[0x5932fe90] -> System[0x59d2b6e0]: 15
06-04 16:17:36.524 D/Mono (26420): Assembly Ref addref Hlx.Mpos.Core[0x58214730] -> System.Collections[0x58246718]: 5
06-04 16:17:36.614 D/Mono (26420): Assembly Ref addref Hlx.Mpos.Core[0x58214730] -> System.Interactive[0x5935eb78]: 2
06-04 16:17:36.619 D/Mono (26420): Assembly Ref addref System.Interactive[0x5935eb78] -> System.Runtime[0x592cd8d8]: 9
06-04 16:17:36.619 D/Mono (26420): Assembly Ref addref System.Interactive[0x5935eb78] -> System.Resources.ResourceManager[0x592c8c20]: 8
[0:]
mvx:Warning: 18.30 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
[0:] mvx:Warning: 18.30 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:17:36.659 I/mono-stdout(26420): mvx:Warning: 18.30 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:17:36.874 D/Mono (26420): Assembly Ref addref Hlx.Mpos.Droid[0x41c96980] -> Hlx.Net.Extensions[0x5821e218]: 3
[0:]
mvx:Warning: 18.58 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
[0:] mvx:Warning: 18.58 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:17:36.934 I/mono-stdout(26420): mvx:Warning: 18.58 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:17:37.294 W/ResourceType(26420): getEntry failing because entryIndex 66 is beyond type entryCount 1
Thread started: #6
[0:]
mvx:Diagnostic: 19.77 Wait starting for
[0:] mvx:Diagnostic: 19.77 Wait starting for
06-04 16:17:38.134 I/mono-stdout(26420): mvx:Diagnostic: 19.77 Wait starting for
Thread started: #7
[0:]
mvx:Diagnostic: 19.91 Wait starting for
06-04 16:17:38.259 I/mono-stdout(26420): mvx:Diagnostic: 19.91 Wait starting for
[0:] mvx:Diagnostic: 19.91 Wait starting for
06-04 16:17:38.414 W/ResourceType(26420): getEntry failing because entryIndex 129 is beyond type entryCount 1
[0:]
MvxBind:Warning: 20.77 Null values not permitted in spinner SelectedItem binding currently
[0:] MvxBind:Warning: 20.77 Null values not permitted in spinner SelectedItem binding currently
06-04 16:17:39.119 I/mono-stdout(26420): MvxBind:Warning: 20.77 Null values not permitted in spinner SelectedItem binding currently
[0:]
==> Rendered UI in ms 2248
[0:] ==> Rendered UI in ms 2248
06-04 16:17:39.204 I/mono-stdout(26420): ==> Rendered UI in ms 2248
06-04 16:17:40.379 D/AbsListView(26420): unregisterIRListener() is called
06-04 16:17:41.324 D/AbsListView(26420): onVisibilityChanged() is called, visibility : 4
06-04 16:17:41.329 D/AbsListView(26420): unregisterIRListener() is called
SECOND RUN (271 ms)
06-04 16:19:53.624 D/AbsListView(26420): onVisibilityChanged() is called, visibility : 0
06-04 16:19:53.624 D/AbsListView(26420): unregisterIRListener() is called
06-04 16:19:53.649 D/AbsListView(26420): unregisterIRListener() is called
06-04 16:19:54.044 E/ViewRootImpl(26420): sendUserActionEvent() mView == null
[0:]
mvx:Diagnostic:158.89 Showing ViewModel ArticleDetailViewModel
[0:] mvx:Diagnostic:158.89 Showing ViewModel ArticleDetailViewModel
06-04 16:19:57.249 I/mono-stdout(26420): mvx:Diagnostic:158.89 Showing ViewModel ArticleDetailViewModel
[0:]
mvx:Diagnostic:159.32 Attempting to load new ViewModel from Intent with Extras
[0:] mvx:Diagnostic:159.32 Attempting to load new ViewModel from Intent with Extras
[0:]
06-04 16:19:57.664 I/mono-stdout(26420): mvx:Diagnostic:159.32 Attempting to load new ViewModel from Intent with Extras
mvx:Diagnostic:159.32 Adding subscription 4efbcbd0-c623-48ab-9172-108d6ae0b036 for ArticleEditDoneMsg
[0:] mvx:Diagnostic:159.32 Adding subscription 4efbcbd0-c623-48ab-9172-108d6ae0b036 for ArticleEditDoneMsg
[0:]
mvx:Diagnostic:159.33 Nothing registered for messages of type MvxSubscriberChangeMessage
06-04 16:19:57.669 I/mono-stdout(26420): mvx:Diagnostic:159.32 Adding subscription 4efbcbd0-c623-48ab-9172-108d6ae0b036 for ArticleEditDoneMsg
[0:] mvx:Diagnostic:159.33 Nothing registered for messages of type MvxSubscriberChangeMessage
06-04 16:19:57.674 I/mono-stdout(26420): mvx:Diagnostic:159.33 Nothing registered for messages of type MvxSubscriberChangeMessage
[0:]
mvx:Warning:159.35 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
[0:] mvx:Warning:159.35 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:19:57.699 I/mono-stdout(26420): mvx:Warning:159.35 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
[0:]
mvx:Warning:159.36 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
[0:] mvx:Warning:159.36 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
06-04 16:19:57.714 I/mono-stdout(26420): mvx:Warning:159.36 using Inflate with a null parent viewGroup is discouraged - see https://github.com/MvvmCross/MvvmCross/issues/507
Thread started: #8
[0:]
mvx:Diagnostic:159.46 Wait starting for
[0:] mvx:Diagnostic:159.46 Wait starting for
06-04 16:19:57.814 I/mono-stdout(26420): mvx:Diagnostic:159.46 Wait starting for
Thread started: #9
[0:]
mvx:Diagnostic:159.50 Wait starting for
[0:] mvx:Diagnostic:159.50 Wait starting for
06-04 16:19:57.849 I/mono-stdout(26420): mvx:Diagnostic:159.50 Wait starting for
[0:]
MvxBind:Warning:159.62 Null values not permitted in spinner SelectedItem binding currently
[0:] MvxBind:Warning:159.62 Null values not permitted in spinner SelectedItem binding currently
06-04 16:19:57.969 I/mono-stdout(26420): MvxBind:Warning:159.62 Null values not permitted in spinner SelectedItem binding currently
[0:]
==> Rendered UI in ms 271
[0:] ==> Rendered UI in ms 271
06-04 16:19:57.984 I/mono-stdout(26420): ==> Rendered UI in ms 271
06-04 16:19:58.054 D/AbsListView(26420): unregisterIRListener() is called
06-04 16:19:58.279 D/AbsListView(26420): onVisibilityChanged() is called, visibility : 4
06-04 16:19:58.279 D/AbsListView(26420): unregisterIRListener() is called