Silverlight windows phone 8.1 FileOpenPicker for all files Continue not working - silverlight

i create silverlight windows phone 8.1 project and i need to choose all kind of file from windows phone
i used FileOpenPicker for choose the file it redirect correctly and i can choose the file this is my code
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add("*");
openPicker.PickMultipleFilesAndContinue();
And i follow this msdn for receiving select
In my case
if i selecting file and come back to the app its every thing working
if i without select any file and come back using mobile hardware back button my app come to home screen. but it need to stay file picker page
my first page
when i press mobile hardware back button in above screen the page redirect to my first page it need to stay in my second page
thanks

Finally i got the answer and avoid redirection
bool reset;
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if(reset && e.uri.tostring().Equals("MainPage.xaml"))
{
e.Cancel = true;
reset = false
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
reset = e.NavigationMode == NavigationMode.Reset;
}

Related

Webview2 website connect to audio has to be manually clicked

I am using wpf webview2 to build an app , the webview2 will navigate to my website which has one button to connect to audio , but i want to make it connect to audio automatically , so i tried use code like
document.getElementById("audioBtn").click(); to try to connect to audio.
But seems this doesn't work, i still have to manually click the button rather than trigger the click by script. (maybe due to some browser security policy ?)
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
So how can i automatically connect to audio ? Both the WPF application and the web application is mine.. so there is no security risk..
thank you so much...
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
You might be trying that click before the content is properly loaded, in which case there will be no document there or element in it.
Assuming this is the problem then you can handle the navigation completed event.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.navigationcompleted?view=webview2-dotnet-1.0.1245.22
Something like:
wv2.CoreWebView2.NavigationCompleted += (s, at) =>
{
wv2.ExecuteScriptAsync("document.getElementById('audioBtn').click();");
};
Before you navigate

CefSharp load a page with browser login

I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.
public MainWindow()
{
InitializeComponent();
BrowserSettings settings = new BrowserSettings();
Cef.Initialize(new CefSettings());
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
licence_grid.Children.Add(webBrowser);
webBrowser.Address = "http://myurlToLoad the page";
}
The problem is when I used a normal url the page load.
But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else.
Can someone give me some tracks to follow...
Thanks
It sounds like the popup you are referring to is in fact the site prompting for basic authentication.
In that case you need to provide an IRequestHandler.GetAuthCredentials handler.
As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.
anybody consuming cefsharp need to implement the authentication dialog. and changes in method is
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
string host, int port, string realm, string scheme, IAuthCallback callback)
{
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
// shyam - original implemenation.
//callback.Dispose();
//return false;
bool handled = false;
// Instantiate the dialog box
AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.
// Open the dialog box modally
dlg.ShowDialog();
if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
{
// The user did not cancel out of the dialog. Retrieve the username and password.
callback.Continue(dlg.UserName,dlg.Password);
handled = true;
}
return handled;
}

Remove 2 Entries from Navigation Journal

In my windows phone 8 app i have to check if user is already login or not before navigating to different pages. If user is not logged in i navigate the user to Login.xaml from where user chooses either login from Facebook or twitter or cancel.
Now when user successfully logs in i navigate the user to appropriate page. My question is how to remove those potential 2 pages (login.xaml and facebook/twitter login)?
NavigationService.BackStack is IEnumerable :(
does anyone has a work around?
If it is the same as using the WPF NavigationService then you can use RemoveBackEntry after you have navigated to the new page.
Update:
If you are using code such as
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
}
Then you can remove the back entries before anyone has a chance to see them
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
//Hide back entry
NavigationService.RemoveBackEntry();
}
However if you are unable to do this, for example when you end up with a Facebook/twitter url in the back entry, then instead subscribe to the Navigated event and then remove them
public Login()
{
NavigationService.Navigated += HideEntriesOnNavigated;
}
void HideEntriesOnNavigated(object sender, NavigationEventArgs e)
{
if (IsFacebookLogin(e.Url)
|| IsTwitterLogin(e.Url)
|| IsAppLoginPage(e.Url))
{
NavigationService.RemoveBackEntry();
}
}

Launch default web browser, but not if URL already open

I have a link on my app UI that launches a URL using System.Diagnostics.Process.Start(). If the user clicks the link several times, it opens several tabs.
Is there a way, maybe a command-line option, to still use the default web browser, but have it just reopen the same tab if the URL is already open? It would be OK if it doesn't work with every possible browser out there, but nice if it at least works with IE, Firefox and Chrome.
I doubt it, but since I didn't see any other questions/answers on this topic, I figured I'd ask.
This is somewhat of a workaround but it might get you started. I have used the System.Diagnostics.Process.ProcessId.
As an example I have used IE, I will explain later why I did this. The code is just "quick and dirty" but I just made it as proof of concept.
I have created a basic WinForm app with one button that will open google in IE, if it has already been opened by the application it will not be opened again.
I added the System.Diagnostics reference.
public int ProcessID;
public Form1()
{
InitializeComponent();
}
private void MyButton_Click(object sender, EventArgs e)
{
if (ProcessID == null)
{
StartIE();
}
else
{
if (!ProcessIsRunning())
{
StartIE();
}
}
}
private bool ProcessIsRunning()
{
bool ProcessRunning = false;
foreach (Process p in Process.GetProcesses())
{
try
{
if (p.Id == ProcessID)
{
ProcessRunning = true;
}
}
catch { }
}
return ProcessRunning;
}
private void StartIE()
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "iexplore.exe";
proc.StartInfo.Arguments = "http://www.google.be";
proc.Start();
ProcessID = proc.Id;
}
This does not completely do what you requested but it might be a good start. There are a few reasons why I did it this way and what possible options are..
If you would use the url as the Filename, it would indeed open up the webpage in the default browser, it would however not return a processID. This is why the snippet shows usage of IE. (If you would use this option, you could use the System.IO.File.Exists to make sure the desired browser is installed)
If you would like to use this option, you can query the registry to pick up what te default browser is, if you have that you could launch that from the value obtained from the registry. If you then change the process.startinfo.filename to this value, then you will launch the default browser but you will still obtain a processId so this might be the way forward. You can check how to do this over here: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/b200903e-ce69-4bd4-a436-3e20a7632dc4
Showing the internet window if it would already be opened, can be done by using the SetForegroundWindow property. As this is already documented in this article, I did not add it in this snippet.
I hope this helps to get you on your way.

C# properties settings works from the second time on

Here's the problem: I've published an app made with Windows Forms with ClickOnce. Therefore, I can't show Terms of Service before install. The client decided to show some Terms of Service page after the install, and if the user agreed with the terms by pressing the button, show the main app. Problem is, after install the app shows the ToS, the user accepts, and after the first restart the user is shown the ToS again! If he accepts, the next time the user opens the app (either after a restart or after the app is closed and opened again) this problem will no longer appear, i.e. if the user agreed to the ToS the main app will show up, without asking the ToS.
The code defining the tos in settings:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool tos {
get {
return ((bool)(this["tos"]));
}
set {
this["tos"] = value;
}
}
The code that checks for ToS when the app starts:
bool tosB = Properties.Settings.Default.tos;
if (!tosB)
{
this.tab_control.SelectTab(this.TOS_PAGE);
this.richTextBox1.Rtf =
global::MyAppName.Properties.Resources.terms_and_conditions;
}
else
{
check_connectivity();
}
The code that runs when the user cliks the I agree button:
private void button2_Click(object sender, EventArgs e)
{
Properties.Settings.Default.tos = true;
Properties.Settings.Default.Save();
Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
key.SetValue("My App Name", Application.ExecutablePath.ToString());
check_connectivity();
}

Resources