Xamarin使用Prism将行为应用于StackLayout
我正试图用StackLayout上单击的日期绑定两个标签。stacklayout有三个元素,一个标签显示日期,另一个标签显示月份和年份,第三个元素是日期选择器,visiblity设置为false 我的XAMLXamarin使用Prism将行为应用于StackLayout,xamarin,xamarin.forms,prism,Xamarin,Xamarin.forms,Prism,我正试图用StackLayout上单击的日期绑定两个标签。stacklayout有三个元素,一个标签显示日期,另一个标签显示月份和年份,第三个元素是日期选择器,visiblity设置为false 我的XAML <StackLayout> <Label Text="End Date" Style="{StaticResource H2Style}" HorizontalOptions="Center"/> <Label Text="26" Hor
<StackLayout>
<Label Text="End Date" Style="{StaticResource H2Style}" HorizontalOptions="Center"/>
<Label Text="26" HorizontalOptions="Center"/>
<Label Text="Mar 2017" HorizontalOptions="Center"/>
<DatePicker x:Name="endDatePicker" IsVisible="false" />
<StackLayout.Behaviors>
<b:EventToCommandBehavior EventName="DateTapped"
Command="{Binding DatePickerCommand}"
CommandParameter= "{x:Reference endDatePicker}" />
</StackLayout.Behaviors>
</StackLayout>
如果有人能帮我解决这个问题,我将不胜感激。这个问题可能是任何线程中的某个未处理异常。 您可能希望通过以下方式捕获真正的异常-
与其试图将焦点放在一个看不见的控件上(这通常是意外的行为),为什么不使用日期选择器作为对话框呢?您可能想要捕捉真正的异常-您的评论和回答帮助我解决了问题。我留下它的方式和现在一样(datepicker隐藏)。将检查其工作方式并采取适当的措施。对于其他有类似问题的人,我强烈建议检查stackoverflow链接和评论,了解如何暴露真正的错误。在我的例子中,是事件名,事件名应该是控件或视图支持的内容。我添加了标记手势,效果很好
public class MyViewModel : BindableBase
{
public DelegateCommand<Object> DatePickerCommand { get; set; }
public MyViewModel()
{
DatePickerCommand = new DelegateCommand<Object>(DateTapped);
}
private void DateTapped(Object obj)
{
Device.BeginInvokeOnMainThread(() =>
{
if (endDatePicker.IsFocused)
endDatePicker.Unfocus();
endDatePicker.Focus();
});
}
}
Objective-C exception thrown. Name: NSInternalInconsistencyException
Reason: Application windows are expected to have a root view
controller at the end of application launch
Native stack trace:
0 CoreFoundation 0x0000000104b7bb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f757141 objc_exception_throw + 48
2 CoreFoundation 0x0000000104b7fcf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000105732536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000109adac46 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3343
5 UIKit 0x0000000109ad77f3 -[UIApplication workspaceDidEndTransaction:] + 182
6 FrontBoardServices 0x000000011246f5f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
7 FrontBoardServices 0x000000011246f46d -[FBSSerialQueue _performNext] + 186
8 FrontBoardServices 0x000000011246f7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
9 CoreFoundation 0x0000000104b21c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
10 CoreFoundation 0x0000000104b070cf __CFRunLoopDoSources0 + 527
11 CoreFoundation 0x0000000104b065ff __CFRunLoopRun + 911
12 CoreFoundation 0x0000000104b06016 CFRunLoopRunSpecific + 406
13 UIKit 0x0000000109ad608f -[UIApplication _run] + 468
14 UIKit 0x0000000109adc134 UIApplicationMain + 159
15 ??? 0x00000001282fcd94 0x0 + 4969188756
16 ??? 0x00000001282fc9dd 0x0 + 4969187805