uwp GridView Drop EventTriggerBehavior 签名
uwp GridView Drop EventTriggerBehavior signature
我正在开发具有多个 ComboBox 和 GridView 的拖放 Xaml Uwp 应用程序。我在 xaml 代码后面对其进行了一些试验,直到我认为我知道我将使用该应用程序前往何处。然后我开始将我的逻辑转移到 ViewModel、PlayPageViewModel 中,我使用的是 MvvM Light 和 Template 10。我有许多使用交互的事件。当我将 Drop 移动到视图模型时,我已经在 codeBehind 中工作了 Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
异常
Exception {System.ArgumentException: Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)
at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)
at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)} System.Exception {System.ArgumentException}
留言
Message "System.ArgumentException: Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.\r\n at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)\r\n at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)\r\n at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)" string
我使用了后面代码中生成的签名。 ContainerContentChanging
在 ViewModel 中触发 正如您看到的注释掉的,我也尝试只使用对象。
正确的签名是什么?
XAML
<GridView x:Name="GvNewPlayList"
RelativePanel.Below="CbPlayListEditor"
Visibility="{Binding LbNewPlayListVisibility}"
Background="BurlyWood"
Padding="5"
Header="New Play List"
ItemsSource="{Binding NewLocalSoundsPlayListsSelectedItem.LocalSfxV2s}"
CanDragItems="True"
AllowDrop="True"
CanReorderItems="True"
IsItemClickEnabled="True"
DragItemsStarting="LbNewPlayList_OnDragItemsStarting"
DragOver="LbNewPlayList_OnDragOver">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Drop">
<core:CallMethodAction MethodName="GvNewPlayList_OnDrop"
TargetObject="{Binding Mode=OneWay}" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="ContainerContentChanging">
<core:CallMethodAction MethodName="GvLocalSoundsPlayListEditorContainerContentChangingAsync"
TargetObject="{Binding Mode=OneWay}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
<GridView.ItemTemplate>
<DataTemplate>
[...]
PlayPageViewModel
在 XAML 试图在虚拟机中定位此方法时引发异常。
// private async void GvNewPlayList_OnDrop(object sender, object e)
// private async void GvNewPlayList_OnDrop()
private async void GvNewPlayList_OnDrop(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Copy;
Logger.Log(this, "yup");
[...]
}
这个从 ContainerContentChanging
事件中触发。
public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()
{
Logger.Log(this, $"GvLocalSoundsPlayListEditorContainerContentChangingAsync: {SelectedPlayList?.PlayListName}");
//_settings.CurrentPlayList = SelectedPlayList;
//LocalSounds = await _theLolFxV2DataServices.GetPlayListAsync(SelectedPlayList);
//NewLocalSoundsPlayListItems = await _theLolFxV2DataServices.GetPlayListAsync(CbPlayListEditorSelectedItem);
}
当使用CallMethodAction调用方法时,方法的签名应该是这样的:public void DoSomthing()
。异常的原因是:
GvNewPlayList_OnDrop标记为private
,需要标记为public
;
不能包含任何参数。
所以只需要像第二种方法一样修改它的签名:public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()
我正在开发具有多个 ComboBox 和 GridView 的拖放 Xaml Uwp 应用程序。我在 xaml 代码后面对其进行了一些试验,直到我认为我知道我将使用该应用程序前往何处。然后我开始将我的逻辑转移到 ViewModel、PlayPageViewModel 中,我使用的是 MvvM Light 和 Template 10。我有许多使用交互的事件。当我将 Drop 移动到视图模型时,我已经在 codeBehind 中工作了 Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
异常
Exception {System.ArgumentException: Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)
at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)
at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)} System.Exception {System.ArgumentException}
留言
Message "System.ArgumentException: Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.\r\n at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)\r\n at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)\r\n at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)" string
我使用了后面代码中生成的签名。 ContainerContentChanging
在 ViewModel 中触发 正如您看到的注释掉的,我也尝试只使用对象。
正确的签名是什么?
XAML
<GridView x:Name="GvNewPlayList"
RelativePanel.Below="CbPlayListEditor"
Visibility="{Binding LbNewPlayListVisibility}"
Background="BurlyWood"
Padding="5"
Header="New Play List"
ItemsSource="{Binding NewLocalSoundsPlayListsSelectedItem.LocalSfxV2s}"
CanDragItems="True"
AllowDrop="True"
CanReorderItems="True"
IsItemClickEnabled="True"
DragItemsStarting="LbNewPlayList_OnDragItemsStarting"
DragOver="LbNewPlayList_OnDragOver">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Drop">
<core:CallMethodAction MethodName="GvNewPlayList_OnDrop"
TargetObject="{Binding Mode=OneWay}" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="ContainerContentChanging">
<core:CallMethodAction MethodName="GvLocalSoundsPlayListEditorContainerContentChangingAsync"
TargetObject="{Binding Mode=OneWay}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
<GridView.ItemTemplate>
<DataTemplate>
[...]
PlayPageViewModel
在 XAML 试图在虚拟机中定位此方法时引发异常。
// private async void GvNewPlayList_OnDrop(object sender, object e)
// private async void GvNewPlayList_OnDrop()
private async void GvNewPlayList_OnDrop(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Copy;
Logger.Log(this, "yup");
[...]
}
这个从 ContainerContentChanging
事件中触发。
public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()
{
Logger.Log(this, $"GvLocalSoundsPlayListEditorContainerContentChangingAsync: {SelectedPlayList?.PlayListName}");
//_settings.CurrentPlayList = SelectedPlayList;
//LocalSounds = await _theLolFxV2DataServices.GetPlayListAsync(SelectedPlayList);
//NewLocalSoundsPlayListItems = await _theLolFxV2DataServices.GetPlayListAsync(CbPlayListEditorSelectedItem);
}
当使用CallMethodAction调用方法时,方法的签名应该是这样的:public void DoSomthing()
。异常的原因是:
GvNewPlayList_OnDrop标记为
private
,需要标记为public
;不能包含任何参数。
所以只需要像第二种方法一样修改它的签名:public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()