2017-05-19 7 views
0

私はXamarin Formsアプリケーション(Prism)でXuni calendar controlを使いたいと思っています。 どうすればいいですか?Prismを使用してViewModelのコマンドにカレンダーコントロールのSelectionChangingイベントをバインドするには、コードを使用したくないためです。 これまでの私のXAMLです。XuniカレンダーSelectionChangingイベントをViewModelにバインドする(Xamarin Forms with Prism)

<xuni:XuniCalendar x:Name="calendar" MaxSelectionCount="-1" Grid.Row="0" Grid.ColumnSpan="2"> 
    <xuni:XuniCalendar.Behaviors> 
     <b:EventToCommandBehavior EventName="SelectionChanging" Command="{Binding SelectionChangingCommand}" 
           EventArgsConverter="{StaticResource selectionChangingEventArgsConverter}" /> 
    </xuni:XuniCalendar.Behaviors> 
</xuni:XuniCalendar> 

これは私のコンバータです:

public class SelectionChangingEventArgsConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var selectionChangingEventArgs = value as CalendarSelectionChangingEventArgs; 
     if (selectionChangingEventArgs == null) 
     { 
      throw new ArgumentException("Expected value to be of type SelectionChangingEventArgs", nameof(value)); 
     } 
     return selectionChangingEventArgs.SelectedDates; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

そしてここでは、私のViewModelにコマンドです:

public DelegateCommand SelectionChangingCommand => new DelegateCommand(SelectionChanging); 

private void SelectionChanging() 
{ 
    throw new NotImplementedException(); 
} 

私はすべてのエラーを得ることはありませんが、ViewModelにでSelectionChangingCommandがトリガされていません。

おかげで、あなたが実際にコンバータを作成する必要はありません ウーヴェ

答えて

1

、あなただけのコマンド、イベント名とEventArgsのパスSelectedDatesを指定する必要があります。

<xuni:XuniCalendar MaxSelectionCount="-1" 
        Grid.Row="0" 
        Grid.ColumnSpan="2"> 
    <xuni:XuniCalendar.Behaviors> 
     <b:EventToCommandBehavior EventName="SelectionChanging" 
            Command="{Binding SelectionChangingCommand}" 
            Path="SelectedDates" /> 
    </xuni:XuniCalendar.Behaviors> 
</xuni:XuniCalendar> 

ViewModelでは、汎用のDelegateCommandを使用してパラメータを受け入れる必要があります。 docs SelectedDatesによるので、あなたは素晴らしい作品あなたのViewModel

public DelegateCommand<List<DateTime>> SelectionChangingCommand { get; } 

public void OnSelectionChangingCommandExecuted(List<DateTime> selectedDates) 
{ 
    // Do stuff 
} 
+0

に次のように必要になりList<DateTime>です。ありがとう!私は "Path"を "EventArgsParameterPath"に置き換えて実行させるだけでした。 –

関連する問題