Incorrect Signature in XAML button clicked event - xaml

I am using Visual Studio 2017 and Resharper 2018.2. I am getting an "Incorrect Signature" error when resharper looks at my code.
<Button x:Name="ButtonNext"
BackgroundColor="#bebebe"
CornerRadius="5"
Grid.Column="1"
Grid.Row="0"
Text="Next"
TextColor="#FFFFFF"
Clicked="ButtonNextClickedAsync"></Button>
Signature is
private async System.Threading.Tasks.Task ButtonNextClickedAsync(object sender, EventArgs e)
It only gives this error when the method is async. Does anyone know what the correct signature is?

Try changing the signature to:
private async void ButtonNextClickedAsync(object sender, EventArgs e)
Then call your task inside this event handler.

Related

uwp GridView Drop EventTriggerBehavior signature

I'm working on a Drag and Drop Xaml Uwp application with multiple ComboBox and GridView. I experimented with it a bit in xaml code behind until I thought I knew where I was heading with the app. I then began moving my logic into a ViewModel, PlayPageViewModel, I'm using MvvM Light and Template 10. I have many events working using interactions. I've had the Drop working in codeBehind when I move it over to the view model I get Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
Exception
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
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
I used the signature that was generated in the code behind. The ContainerContentChangingis fired in the ViewModel As you can see commented out I tried with just object too.
What is the correct signature?
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
Exception fired on XAML attempting to target this method in the vm.
// 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");
[...]
}
This one fires from the ContainerContentChanging event.
public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()
{
Logger.Log(this, $"GvLocalSoundsPlayListEditorContainerContentChangingAsync: {SelectedPlayList?.PlayListName}");
//_settings.CurrentPlayList = SelectedPlayList;
//LocalSounds = await _theLolFxV2DataServices.GetPlayListAsync(SelectedPlayList);
//NewLocalSoundsPlayListItems = await _theLolFxV2DataServices.GetPlayListAsync(CbPlayListEditorSelectedItem);
}
When using a CallMethodAction for invoking a method, the signature of the method should be like this: public void DoSomthing(). The reasons for the exception are:
GvNewPlayList_OnDrop is marked as private, it need mark as public;
It cannot contain any parameters.
So just modify its signature like that of the second method: public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()

Replicate Hardware Back Button Functionality from UI in Windows Phone

I'm trying to write a windows phone application and am wondering if it's possible to have a software button in the UI that does the same thing as the hardware back button (just sends a system back command). I can't seem to find any information on how to do this online.
try this:
XAML:
<Button x:Name="btnBack" Content="Back" Click="btnBack_Click"></Button>
CS:
private void btnBack_Click(object sender, RoutedEventArgs e)
{
if (NavigationService.CanGoBack)
NavigationService.GoBack();
else
App.Current.Terminate();
}
This would work as same Back button. if any back-state is there it would go to that state or if not it would close (Terminate) the Application.
you can override the back button function
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
//Do your work here
base.OnBackKeyPress(e);
}

How to navigate from one page to another in Windows phone 8 using XAML?

I am trying to make my first WP8 app but, i got a problem. I try to navigate to another page using the code below, but VS12 throws a error.
What am I doing wrong?
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
}
Your code is correct for navigating, just make sure the Page 'BMI_Bereken.xaml' actual exists at the root of your project.
Clean solution first and then rebuild again (right click on project/solution -> clean)
Then if it still crashes, try to use System.Windows.RoutedEventArgs e instead of RoutedEventArgs e
Guys i found the problem.
I use a self made button style for my buttons and i got on the visualstate pressed some wrong code. In fact I was trying to set the background collor of the button in the place of the name target name.
See the code below for what i did wrong.
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="#FF009AD3">
I know very stupid, but I want to thank everyone for the help.
Try this
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
this.NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
});
}
You could do something like this:
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (txtDriverId.Text == "D0001" && txtPassword.Password == "open")
{
Frame.Navigate(typeof(VehicleCondition));
}
}

Auto Repeat a MediaElement

I'm trying to auto repeat a MediaElement. I did that using the following code:
<MediaElement Name="MainMedia" MediaEnded="MainMedia_MediaEnded_1" />
private void MainMedia_MediaEnded_1(object sender, RoutedEventArgs e)
{
MainMedia.Position = TimeSpan.FromSeconds(0);
MainMedia.Play();
}
But I was wondering if there is any better solution.
There is a property called IsLooping. If you set that to true it will auto repeat the media.

Cannot navigate to another page

I have a button and a tapped event:
private void btnSetLocationName_Click_1(object sender, RoutedEventArgs e)
{
ApplicationModel.LocationName = locationName.Text;
Frame.Navigate(typeof(GroupsPage));
}
I want to just navigate to another page. Unfortunately, Frame.Navigate does not work. I have also tried to make sure it runs in the GUI thread:
await this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => Frame.Navigate(typeof(GroupsPage)));
However, it should do, as the click handler for the button runs in the GUI thread.
The following error occurs:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
OK, after commenting out bits of code until it worked, it turns out I had an empty OnNavigatedTo override:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//base.OnNavigatedTo(e);
}
If you uncomment base.OnNavigatedTo it now works.
I think what threw me was that the error occurred when navigating FROM a page with this empty override. Also, the cryptic error message didn't help much.