Hi I am building an app using Xamarin forms PCL project. In this app, I want to prevent users from taking screenshot so for android I tried-
this.Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
In mainactivity.cs
For windows 10 and 8.1 I found-
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
I tried to put it in MainPage.xaml.cs in UWP project. but my app dont start at all after this. Only splash screen is shown.
Where to place this line of code?
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false;
LoadApplication(new FISE.App());
}
}
are you calling somewhere Window.Current.Activate() ? this should be in the App.xaml.cs
I am developing Windows phone 8.1 Silver Light Application. In the application there are so many screens. Pages are navigating perfectly.
My issue is when i press on back button(Windows Phone Back Button) The pages are going back to the previous pages. I want to stop back button navigation in my application. I followed below link but i am not succeeded.
https://social.msdn.microsoft.com/Forums/windowsapps/en-us/131a99ce-53a4-4389-81e9-7801af57b78b/used-hardwarebuttonsbackpressed-handler
Could any one advise me.
Try this for back button on your XAML.cs page :
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
}
I have an AutoSuggestBox in a XAML Page for a Windows Phone 8.1 app and when i click on the AutoSuggestBox the whole page goes up. Does anyone know how to disable this feature?
Thanks
Edit:
Here is the code fix, thank you Peter Torr - MSFT.
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing += (s, args) =>
{
args.EnsuredFocusedElementInView = true;
};
You need to handle the InputPane.Showing event, and set the EnsuredFocusedElementInView property to true. This will stop Windows from trying to make the item come into view.
The WinRT WebView control in both Windows 8.1 and Windows Phone 8.1 does not update its Source property in response to history.pushState or history.replaceState, which can modify the current URL from JavaScript without actually navigating to a different page.
You can easily verify this by creating a new blank app, adding a WebView control named WebView to MainPage.xaml and replacing the constructor with the following:
public MainPage()
{
this.InitializeComponent();
var timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
timer.Tick += (o, e) => Debug.WriteLine("WebView.Source: " + WebView.Source);
timer.Start();
// you could also replace the URL with a simpler demo page like this one:
// http://www.skjapp.com/wp-content/uploads/2012/06/HistoryAPI-pushState.htm
WebView.Navigate(new Uri("http://try.discourse.org"));
}
Opening any discussion thread on Discourse will not update WebView.Source. The native IE browser handles this correctly, and strange enough the old Windows Phone Silverlight WebBrowser control does as well.
So, am I doing something wrong or is there any other way to get the current URL of a WebView that properly supports the HTML5 history API?
I finished to develop an XNA game, then I created the Monogame project, and tested it on my device. Now I made some other pages such as an "about" page. How can I go to that page considering I have a Monogame project and just an XNA code? In particular inside my game I made a Main Menu where you can click the "about" button and know if someone has clicked: how can I link that event to the "go to about.xaml" function?
Inside XNA, update method:
if (about_button.IsClicked())
{
// Go to about.xaml
}
I tried:
if (about_button.IsClicked())
{
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri("/About.xaml", UriKind.Relative));
}
But it throws: System.UnauthorizedAccessException
I haven't tried this myself, but the WP framework has the Window.Current.Content object which you can use to load different views.
For example:
// Create a Frame to act navigation context and navigate to the first page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(BlankPage));
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
So if you are using a windows phone 8 project template, with that object you can easily tell the application to load a xaml view or the game one.
You can also check how to do it with WinRT and monogame on this site (the Window.Current is part of the WP and WinRT framework). Here, you will find how to integrate both frameworks in order to create a monogame using the WinRT xaml views :)
For more information on the Window.Current, check this link.
EDIT
If you used a monogame for windows phone template, a XAML page should already exist in your project which is used to load the game itself, as well as a media element for video and sound playback.
The page is called "GamePage.xaml", which you could use for your navigational purposes.
This info was taken from the "Windows 8 and Windows Phone 8 Game Development" book written by Adam Dawes (chapter 13).
In the case of the Windows Phone projects, GamePage is implemented as
a normal page. [...]
Within the Windows Phone page is a full-page
Grid control, inside which is another full-screen control of type
DrawingSurface. This is a type of control that DirectX can use to
render graphics to a Windows Phone page. Our XAML content can also be
placed into the Grid. A MediaElement control is present within the
Grid, too. MonoGame uses this for some of its audio playback
functionality.
On both platforms, the way that XAML and DirectX have been designed to
interact is that the DirectX rendering is processed first. Once this
has been completed, the XAML renderer then takes control and adds its
content as a second step, prior to presenting the final rendered page
to the user. As a result, XAML content will always appear in front of
any graphics rendered by MonoGame. This ensures that any XAML controls
we use as our user interface (for control buttons, text displays, and
so on) will appear unobstructed in front of the game graphics.
The XAML rendering still takes any transparency within the controls
into account, so it is quite possible to have controls that are
partially transparent or that use alpha shading. These will blend in
front of the MonoGame graphics, as you would expect them to.
With this into account, you should be able to throw an event from your game class (monogame), the xaml page can suscribe itself to it and then, when captured, render your xaml page (maybe a user control would be wiser as you won't navigate away from the main game page).
Hopefully, this will help you with your problem.
Try to create a frame in your gamepage
public static Frame RootFrame { get; private set; }
then in your click event put these lines
RootFrame = new Frame();
RootFrame.Navigate(typeof(about));
did this work?
You receive that error because the call has to be made from the UI thread like this:
Deployment.Current.Dispatcher.BeginInvoke(() =>
(App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Pages/MenuPage.xaml", UriKind.Relative)));
Also, make sure you dispose of the game object when unloading the game xaml page. You to this by subscribing to the Unloaded event of the GamePage and calling Dispose on the game object. See below:
public partial class GamePage : PhoneApplicationPage
{
private LoonieGame _game;
public GamePage()
{
InitializeComponent();
_game = XamlGame<LoonieGame>.Create("", this);
this.Unloaded += GamePage_Unloaded;
}
void GamePage_Unloaded(object sender, RoutedEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => _game.Dispose());
}
}