I have been trying to embed a ContentPage in UWP following this tutorial
My code is rather simple, here is my content page :
<?xml version="1.0" encoding="utf-8" ?>
<local:CustomContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NavigationPannel2.PageTest1"
xmlns:local="clr-namespace:NavigationPannel2"
BackgroundColor="Aqua">
<ContentPage.Content>
<Grid>
<Button Text="To Page 2"
Clicked="Button_Clicked"/>
</Grid>
</ContentPage.Content>
</local:CustomContentPage>
(CustomContentPage just adds a custom navigation event :)
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace NavigationPannel2
{
public class CustomContentPage : ContentPage
{
public EventHandler<NavigateEvent> navigation_push_event;
public CustomContentPage()
{
}
}
}
I initialize Forms.Init() in OnLaunched :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace NavigationPannel2.UWP
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Xamarin.Forms.Forms.Init(e);
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
And I use this page as content for my UWP MainPage :
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Xamarin.Forms;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
using Windows.UI.Core;
namespace NavigationPannel2.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
LoadApplication(new NavigationPannel2.App());
CustomContentPage page = new PageTest1();
Content = page.CreateFrameworkElement();
}
}
}
But the page seems to have lost its dynamic layout : when i resize the window everything stays still…
How Can I solve this ?
Related
ideally need to extract all the invoice in xls format of website, storing in SharePoint. I am using Docker for pulling the python code, firefox, and gecko driver.
when i call the logic app http trigger it gives the timeout error but all the invoices can store in the Sharepoint logic app ran and gives failed.
within 2 min limit, gives succeeded results (trigger history fired).
I am using HTTP trigger and function app URL.
how to use Webhook or any other solution to call long-running logic app successful results.
For your requirement, you can use "HTTP Webhook" in your logic app. But you also need to modify your function code. Here provide a sample of the code for your reference. The sample is not a azure function, but you can refer to it to modify your function code. Please pay attention to the below code of the sample.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
namespace LogicAppTriggers.Controllers
{
public class WebhookTriggerController : ApiController
{
public static List<string> subscriptions = new List<string>();
/// <summary>
/// Recieve a subscription to a webhook.
/// </summary>
/// <param name="callbackUrl">URL to get from Logic Apps - #listCallbackUrl()</param>
/// <returns></returns>
[HttpPost, Route("api/webhooktrigger/subscribe")]
public HttpResponseMessage Subscribe([FromBody] string callbackUrl)
{
subscriptions.Add(callbackUrl);
return Request.CreateResponse();
}
/// <summary>
/// Fire all triggers - do a GET to this API to fire all triggers subscribed
/// </summary>
/// <returns></returns>
[HttpGet, Route("api/webhooktrigger/trigger")]
public async Task<HttpResponseMessage> Get()
{
using (HttpClient client = new HttpClient())
{
foreach (string callbackUrl in subscriptions)
await client.PostAsync(callbackUrl, #"{""trigger"":""fired""}", new JsonMediaTypeFormatter(), "application/json");
}
return Request.CreateResponse(HttpStatusCode.Accepted, String.Format("There are {0} subscriptions fired", subscriptions.Count));
}
/// <summary>
/// Unsubscribe
/// </summary>
/// <param name="callbackUrl"></param>
/// <returns></returns>
[HttpPost, Route("api/webhooktrigger/unsubscribe")]
public HttpResponseMessage Unsubscribe([FromBody] string callbackUrl)
{
subscriptions.Remove(callbackUrl);
return Request.CreateResponse();
}
}
}
Then you can use "HTTP Webhook" like below:
How I can make my Xamarin.Forms UWP application have its main window maximized upon its launch?
You should use this answer: Maximize UWP app window on launch as #Dishant says but you should add this code to method OnLaunched into App class into App.xaml.cs file of your project UWP and add correct namespaces like this:
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
/* ************** CALL METHOD HERE ************** */
MaximizeWindowOnLoad();
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
/* ************** SEE HERE ************** */
private void MaximizeWindowOnLoad()
{
var view = DisplayInformation.GetForCurrentView();
// Get the screen resolution (APIs available from 14393 onward).
var resolution = new Size(view.ScreenWidthInRawPixels, view.ScreenHeightInRawPixels);
// Calculate the screen size in effective pixels.
// Note the height of the Windows Taskbar is ignored here since the app will only be given the maxium available size.
var scale = view.ResolutionScale == ResolutionScale.Invalid ? 1 : view.RawPixelsPerViewPixel;
var bounds = new Size(resolution.Width / scale, resolution.Height / scale);
ApplicationView.PreferredLaunchViewSize = new Size(bounds.Width, bounds.Height);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
Currently, I have a Desktop application that has some of its views available to Mobile. I added the ability to switch between Desktop and Mobile versions. However, if the user is on a page that does not have a mobile version and switches to Mobile, a bunch of bad things happen... Is there some way to tell MVC4 to go to a "Sorry, this isn't implemented on Mobile yet" page if a mobile version of the current view does not exist?
Thanks!
This is what I ended up doing. I created a HasMobileVersion attribute to decorate all View methods that have a corresponding mobile version. Instead of showing a "sorry" page, I just redirect the user to the root URL (mobile version must exist there). Here is the code for it:
/// <summary>
/// This attribute specifies which views have Mobile versions available.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class HasMobileVersionAttribute : ActionFilterAttribute
{
#region << Constructors >>
/// <summary>
/// Default constructor.
/// </summary>
public HasMobileVersionAttribute()
{
// Nothing to do
}
#endregion
#region << Overridden Methods >>
/// <summary>
/// Allows a View to switch between mobile and desktop versions, ensuring that if a page does not have a mobile version that
/// it sends the user to the root page.
/// </summary>
/// <param name="ac">Request data.</param>
public override void OnActionExecuting(ActionExecutingContext ac)
{
ac.Controller.ViewBag.HasMobileVersion = true;
}
#endregion
}
There is a link that we declare (well, icon) that allows the user to switch between Mobile and Desktop. This link will check for HasMobileVersion == true from the ViewBag. If it is, it will use the current URL as the return URL once the user is in Mobile mode. If this does not exist, then we force the return URL the Mobile link will use to be the root of the site "/". You have to go out of your way to decorate all the Views that have Mobile pages, but it works nicely.
EDIT:
To switch between Mobile/Desktop, we have a ViewSwitcher controller. If you are in the _Layout, obviously you will switch to the Mobile version. If you are in _Layout.Mobile, you would go to desktop. The attribute is only used to determine if the current page has a Mobile version available for viewing. On the Mobile side, the desktop version is always present (otherwise, you'd have to make a HasDesktopVersion attribute, too). Here is that code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.WebPages;
using System.Web.Mvc;
public class ViewSwitcherController : Controller
{
#region << Views >>
/// <summary>
/// Allows the user to swicth between mobile and desktop versions of the site.
/// </summary>
/// <param name="mobile">True if the user should view the mobile version; false if the user should view the desktop version.</param>
/// <param name="returnUrl">Original URL.</param>
/// <returns>RedirectResult to original URL.</returns>
public RedirectResult SwitchView(bool mobile, string returnUrl)
{
if (Request.Browser.IsMobileDevice == mobile)
HttpContext.ClearOverriddenBrowser();
else
HttpContext.SetOverriddenBrowser(mobile ? BrowserOverride.Mobile : BrowserOverride.Desktop);
return Redirect(returnUrl);
}
#endregion
}
Here is the Razor for the URL to get the talked about result:
#Url.Action("SwitchView", "ViewSwitcher" , new { mobile = true, returnUrl = ViewBag.HasMobileVersion != null && ViewBag.HasMobileVersion ? Request.Url.PathAndQuery : "/" })
On the mobile side, mobile would = false.
So here's my predicament. I'm writing a custom, one-off content management system, and I can not for the life of me getting this method to work correctly. What I want to do is create a laundry list worth of methods in separate folders and call them as I need them on whichever web forms I want to call them on.
I created a WebApp and created a folder inside of the app called App_Code. Inside of App_Code, there is a public class called "TestimonialService". Here it is:
/******************** TESTIMONIAL SERVICE ****************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlueTreeSecurity.App_Code.Data;
namespace BlueTreeSecurity.App_Code.Testimonials
{
public class TestimonialService
{
private readonly CMSObjectContext _context;
public TestimonialService(CMSObjectContext context)
{
this._context = context;
}
#region methods
/// <summary>
/// Gets all testimonials
/// </summary>
/// <returns>testimonial collection</returns>
public List<Testimonial> GetAllTestimonials()
{
var query = from t in _context.Testimonials
orderby t.DisplayOrder ascending
select t;
if (query.Count() > 0)
{
var testimonial = query.ToList();
return testimonial;
}
else
{
return null;
}
}
#endregion
}
}
Then on the actual aspx.cs page I call said function like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BlueTreeSecurity.App_Code;
using BlueTreeSecurity.App_Code.Data;
using BlueTreeSecurity.App_Code.Testimonials;
namespace BlueTreeSecurity
{
public partial class Testimonials : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Title = "Testimonials | ...";
Bind_Data();
}
protected void Bind_Data()
{
/** when i try to use intellisense here it's not recognized. **/
var testimonials = TestimonialService.GetAllTestimonials();
rptTestimonials.DataSource = testimonials;
rptTestimonials.DataBind();
}
}
}
The exact error spat back is this:
Error 1
An object reference is required for the non-static field, method, or property
'BlueTreeSecurity.App_Code.Testimonials.TestimonialService.GetAllTestimonials()'
Anything would be appreciated, guys. I'm ripping my hair out here.
Here's the Project structure
- Blue Tree Security (main project)
- App_Code
+ Data
+ Testimonials
+ TestimonialService.cs
Rest of the .aspx, .aspx.cs, and .ascx files.
If i'm not totally misinterpreting here, the error message you are getting is telling you what the problem is. Make GetAllTestimonials() static or instantiate a TestimonialService instance.
protected void Bind_Data()
{
var testimonialService = new TestimonialService(yourContextObect);
var testimonials = testimonialService.GetAllTestimonials();
rptTestimonials.DataSource = testimonials;
rptTestimonials.DataBind();
}
I have a CustomRequestContext object that has to be disposed after each request. I create it in Page_Load and dispose of it in Page_Unload. The only issue is that in certain circumstances I need to call Server.Transfer to redirect to another aspx page instead. In this case, the object should not be unloaded until the new page is ready to be unloaded. What is the nicest way of achieving this?
create a custom PageBase class for all your asp.net pages as mention below and Dispose the CustomRequestContext on the Page_Load and Page_Unload event.
/// <summary>
/// Base of front end web pages.
/// </summary>
public class PageBase : System.Web.UI.Page
{
/// <summary>
/// Initializes a new instance of the Page class.
/// </summary>
public Page()
{
this.Load += new EventHandler(this.Page_Load);
this.UnLoad += new EventHandler(this.Page_UnLoad);
}
/// <summary>
/// Page Load
/// </summary>
/// <param name="sender">sender as object</param>
/// <param name="e">Event arguments</param>
private void Page_Load(object sender, EventArgs e)
{
try
{
//Dispose the object here, assuming it is IDisposable.
//You can apply your own Disposition steps here..
CustomRequestContext.Dispose();
}
catch
{
//handle the situation gracefully here.
}
}
/// <summary>
/// Page UnLoad
/// </summary>
/// <param name="sender">sender as object</param>
/// <param name="e">Event arguments</param>
private void Page_UnLoad(object sender, EventArgs e)
{
try
{
//Dispose the object here, assuming it is IDisposable.
//You can apply your own Disposition steps here..
CustomRequestContext.Dispose();
}
catch
{
//handle the situation gracefully here.
}
}
}
I solved this problem by allowing the object to be owned by one page at a time. If I wanted to relinquish control from a page, I would set it equal to null and then it would not be released in the page's destructor.