【发布时间】:2017-10-19 02:39:46
【问题描述】:
我想在我的 Xamarin Forms 应用程序 (Prism) 中使用 Xuni calendar control。 我如何使用Prism 将日历控件的 SelectionChanging 事件绑定到我的 ViewModel 中的命令,因为我不想使用后面的代码。 到目前为止,这是我的 XAML。
<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 没有被触发。
谢谢, 乌韦
【问题讨论】:
标签: xaml xamarin mvvm xamarin.forms prism