2017-09-19 29 views
0

我正試圖將兩個標籤與點擊StackLayout上的日期進行綁定。 stacklayout有三個元素,一個是顯示日期的標籤,另一個是顯示月份和年份的標籤,第三個元素是可見性設置爲false的日期選擇器。Xamarin使用Prism將行爲應用於StackLayout表格

我的XAML

<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> 

我想顯示在stackLayout的點擊日期選擇器對話框。

我的視圖模型

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 

,我將不勝感激,如果有人可以幫助我這個

+1

你可能想以趕上真正的例外 - https://stackoverflow.com/q/43556274/1155650 –

回答

1

的問題可能是未處理的異常某處任何線程。 您可能希望通過以下這個捕捉真正的例外 - Forms with Prism: Application windows are expected to have a root VC

而不是試圖將焦點設置於一個無形的控制,大多是意外的行爲,爲什麼不使用日期選取器作爲一個對話框ACR User Dialogs for Xamarin and Windows

+1

您的評論和答案幫助我解決了這個問題。我把它和現在一樣(日期選擇器隱藏)。我們將檢查它的工作原理並採取適當的措施。對於任何有類似問題的人,我強烈建議檢查stackoverflow鏈接評論,以瞭解如何暴露真實錯誤。就我而言,它是事件名稱,事件名稱應該是控件或視圖支持的內容。我添加了標記手勢,它的工作原理 –

相關問題