I am trying to add UIScreenEdgePanGesture in Xamarin for iOS. But it crashes. I am using following code
UIScreenEdgePanGestureRecognizer rightEdgeGesture = new UIScreenEdgePanGestureRecognizer (HandleRightEdgeGesture);
rightEdgeGesture.Edges = UIRectEdge.Right;
View.AddGestureRecognizer (rightEdgeGesture);
and also handle action
public void HandleRightEdgeGesture(UIScreenEdgeGestureRecognizer recognizer){
Console.WriteLine("Screen to right");
}
Please help me if I am writing any wrong syntax.
Related
I am kind of new to Xamarin development. I tried to change the back button behavior with a binding command, but that didn't seem to work. This is the code for the view:
<Shell.BackButtonBehavior>
<BackButtonBehavior Command="{Binding GoBack}"/>
</Shell.BackButtonBehavior>
And this is the code for the view model:
public CreatePasswordVM()
{
_goBack = new Command(GoBackButton);
}
private ICommand _goBack;
public ICommand GoBack
{
get { return _goBack; }
}
public async void GoBackButton()
{
await Shell.Current.GoToAsync("../..");
}
When I pressed the back button, the method "GoBackButton" didn't call. I want to mention that on Android works.
Shell BackButtonBehavior command binding not working in UWP
Derive from Xamarin Form source code. BackButtonBehavior has not implemented for UWP platform, we could find Android and IOS implementation here and here. But for uwp there is not such tracker and there is not such value in the UWP ShellRenderer. For this scenario, we suggest your post new feature request in the Xamarin Forms github.
I created a xamarin forms project which is using oxyplot and Rg.Plugins.Popup xamarin forms.
However, the graph does not work as excepted. I modified code refer to the link, but graph not show on UWP .
In addition, I init Rg.Plugins.Popup and oxyplot with follow code, I don't know what I doing wrong. Please help. thanks in advance.
in UWP project App.xaml.cs
Xamarin.Forms.Forms.Init(e, Rg.Plugins.Popup.Popup.GetExtraAssemblies());
List<Assembly> assembliesToInclude = new List<Assembly>();
//Now, add in all the assemblies your app uses
assembliesToInclude.Add(typeof(OxyPlot.PlotModel).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.PlotController).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Windows.PlotView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Xamarin.Forms.PlotView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer).GetTypeInfo().Assembly);
try
{
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
// replaces Xamarin.Forms.Forms.Init(e);
}
catch (Exception ex) { }
OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer.Init();
Xamarin forms and oxyplot version is
OxyPlot.Xamarin.Forms : 1.1.0-unstable0011
Xamarin.Forms: 4.2.0.709249
If you want to use both of them, you could insert their assemblie in the same list. For more please refer the following.
List<Assembly> assembliesToInclude = new List<Assembly>();
Popup.Init();
OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer.Init();
assembliesToInclude.Add(typeof(OxyPlot.PlotModel).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.PlotController).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Windows.PlotView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Xamarin.Forms.PlotView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(OxyPlot.Xamarin.Forms.Platform.UWP.PlotViewRenderer).GetTypeInfo().Assembly);
var assemblies = Popup.GetExtraAssemblies();
assembliesToInclude.AddRange(assemblies);
var count = assembliesToInclude.Count;
try
{
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
}
catch (Exception ex) {
}
I've been working on this Xamarin Forms mobile application and I've been loving it but it's a media player application and the native embedding for the platform specific video player doesn't work. After much debugging I was able to get the audio playing but no video would show up. I think this has to do with the views just not being swapped out appropriately. Unfortunately there isn't much material on how to effectively switch from a Xamarin Forms view to a native view (to see the video) through Xamarin Forms. Any help is appreciated thank you !
I was able to get iOS videos working by using the Xamarin Forms messaging service to Appdelegate class and built the AVPlayer class there. Works great.
playVideo.Clicked += (sender, e) =>
MessagingCenter.Send(this, "ShowVideoPlayer", new
ShowVideoPlayerArguments(videoUrl));
Appdelegate.cs
MessagingCenter.Subscribe<VideoDetailPage,
ShowVideoPlayerArguments>(this, "ShowVideoPlayer",
HandleShowVideoPlayerMessage);
//messaging center class
private void HandleShowVideoPlayerMessage(Page page,
ShowVideoPlayerArguments arguments)
{
var presentingViewController = GetMostPresentedViewController();
var url = NSUrl.FromString(arguments.Url);
var avp = new AVPlayer(url);
var avpvc = new AVPlayerViewController();
avpvc.Player = avp;
avp.Play();
presentingViewController.PresentViewController(avpvc, animated: true,
completionHandler: null);
}
private UIViewController GetMostPresentedViewController()
{
var viewController =
UIApplication.SharedApplication.KeyWindow.RootViewController;
while (viewController.PresentedViewController != null){
viewController = viewController.PresentedViewController;
}
return viewController;
}
However.. Getting this to work with Android is a whole different animal since I have to have deal with .axml layouts I believe.. Any help with this would be greatly appreciate.. Thanks so much guys.
So I figured out an implementation using Native Views, an alternative to Custom Renderers. Such a more stream lined process.
Check my action bar image here(My requirement)i want to display the custom text label button on xamarin.android action bat(material theme),is there any possibility to do that in xamarin.android please suggest ...
static Button notifCount;
static int mNotifCount = 0;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
View count = menu.findItem(R.id.badge).getActionView();
notifCount = (Button) count.findViewById(R.id.notif_count);
notifCount.setText(String.valueOf(mNotifCount));
return super.onCreateOptionsMenu(menu);
}
private void setNotifCount(int count){
mNotifCount = count;
invalidateOptionsMenu();
}
i tried above code converting into xamarin.android but it is showing like..
View count= menu.FindItem(Resource.Id.badge).getActionView ...Error...getActionview is not there in xamarin.
Check out my post about this on the Xamarin Forums. Just did this recently for Push Notifications, though I am not sure if your badge is for Push or Local Notifications. I am using Xamarin Forms so it may be a little different from you but let me know if you have any issues.
Basically, in OnCreateOptionsMenu you make sure you are on your specific page, then inflate your custom badge into the action bar and then add a custom action.
Then in OnPrepareOptionsMenu you can update the badge count. I used the DB to figure out what the new badge value should be.
https://forums.xamarin.com/discussion/comment/183694/#Comment_183694
*Edit: I also found this link recently but have not looked into it much. Might also be helpful.
we were using the Notifier Plugin in our application to show the Notification for our Xamarin Forms application.
Notifier Plugin URL: https://github.com/edsnider/Xamarin.Plugins/tree/master/Notifier
For customizing the Notification Navigation with Android Platform,
Changes made in Plugin.LocalNotifications.Android Source as :
In LocalNotificationsImplementation as "var resultIntent = new Intent(Application.Context,typeof(RedirectActivity));"
In RedirectActivity Activity, we have included "MessagingCenter.Send("SampleAppNotificationNavigation", "RedirectToNavigationPage");"
Changes made in MyApplication.Android Source as :
In our Android application we subscribed messaging center as " MessagingCenter.Subscribe(this, "RedirectToNavigationPage", message =>
{
LoadApplication(new NextPage());
});"
Note: Based on the suggestion from Native to Forms Page Navigation we have implmented the same.
https://github.com/xamarin/xamarin-forms-samples/tree/master/Native2Forms
In our core project App page we have included as "
public class NextPage : Application
{
public NextPage()
{
MainPage = new NavigationPage(new ConfigureServer());
}
}"
Everything is working as expected (till ConfigureServer page constructor and intializecomponent() riased ) but failed to launch the ConfigureServer Page.
Kindly guide us to proceed further.
Thanks in advance.