How can I link my web address www.facebook.com to my hyperlink button.and that should load in my app page.
You can only load a web page inside a WebView control. Put it somewhere on your page first:
<WebView x:Name="MyWebView" />
In the click event handler of your Hyperlink load the page into this WebView:
private void Hyperlink_OnClick(object sender, RoutedEventArgs e)
{
MyWebView.Navigate(new Uri("http://www.facebook.com"));
}
Process.Start("http://facebook.com"); that will load the default browser at facebook.com is this what you require ?
how about the launcher class ? You can use the Launcher class to launch a document in the default handler, i.e load a website with the default browser, from what i understand you cant just create a process.
async void DefaultLaunch()
{
// Path to the file in the app package to launch
string imageFile = #"images\test.png";
var file = wait Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
if (file != null)
{
// Launch the retrieved file
var success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not find file
}
}
Related
I've a custom file. Serialization and deserialization is working
fine when using my custom functions
File > Save
File > Open
When I'm going directly in the windows explorer on my file
and want to open it with the program it's not deserializing.
How can I handle the deserialization from "outside"?
Thanks for your help.
When a file is opened from Windows Explorer with your app, the absolute path of the file is passed as the first command line argument.
In case of WPF, you can handle the Startup event of App to intercept such an argument for later opening in MainWindow.
// App.xaml.cs
public string FileToOpen;
public App()
{
Startup += (sender, e) =>
{
if (e.Args.Length > 0)
FileToOpen = e.Args[0];
};
}
// MainWindow.xaml.cs
public MainWindow()
{
var path = (Application.Current as App).FileToOpen;
if (path != null)
{
// TODO: open the file when appropriate
}
}
I created an WPF application the use a viewer for file I set the application as default application for this application (filename.myapp), now if I try to open the file it will start the application but I need to know how to get this file location and name so I can use it in the application.
If I understood your question correctly you want to know the name of the file that was double-clicked/opened with your application associated.
It is the second item in the args array of your start up event:
private void Application_Startup(object sender, StartupEventArgs e)
{
...
if(e.Args.Length > 1)
{
var filename = e.Args[1]);
}
...
}
This is how I did it in the end:
var args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
var fileName= args[1];
}
I need to change start page in my app depending on logged user or not. In Silverlight 8.1 version all what I need to do is delete starting page in manifest file and in App.xaml.cs:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
Uri uriMain = new Uri("/PivotPage.xaml", UriKind.Relative);
Uri uriLogin = new Uri("/MainPage.xaml", UriKind.Relative);
var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("user_id"))
{
RootFrame.Navigate(uriLogin);
}
else
{
RootFrame.Navigate(uriMain);
}
}
But in universal version I can't figure out how can I do it. What I need to do to achive this in WP 8.1universal app?
EDIT:
Found a duplicate Change default startup page for windows phone 8.1 app, sorry
In App.xaml.cs look for
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// ...
// launch codes
// insert here
// Ensure the current window is active
Window.Current.Activate();
}
My launch code detects to see if they're on the Phone or not, so I have a starting page that is
different for each platform
#if WINDOWS_PHONE_APP
if (!rootFrame.Navigate(typeof(PhonePage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
#endif
#if WINDOWS_APP
if (!rootFrame.Navigate(typeof(DesktopPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
#endif
I'm currently developing a metro app in which the user can change current language at runtime and all the custom controls that are loaded must update their text regarding to the new language. Problem is that when I change the language using the following code, the app language changes but it will only update text when I restart my app because the pages and controls that are already rendered are cached.
LocalizationManager.UICulture = new System.Globalization.CultureInfo((string)((ComboBoxItem)e.AddedItems[0]).Tag);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = ((ComboBoxItem)e.AddedItems[0]).Tag as String;
What should I do to force updating text of all custom controls at runtime without restarting my app?
Use this:
var NewLanguage = (string)((ComboBoxItem)e.AddedItems[0]).Tag;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = NewLanguage;
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
//Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceManager.Current.DefaultContext.Reset();
and then reload your Page, using Navigate method:
if (Frame != null)
Frame.Navigate(typeof(MyPage));
In order to respond right away, you would need to reset the context of the resource manager.
For Windows 8.1:
var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
resourceContext.Reset();
You will still need to force your page to redraw itself and thus re-request the resources to get the changes to take place. For Windows 8, you can see https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx
You can change the app's language at runtime with the help of this source code. I took help from this and manipulated my app's language settings page as follows:
In languageSettings.xaml.cs:
public partial class LanguageSettings : PhoneApplicationPage
{
public LanguageSettings()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (ChangeLanguageCombo.Items.Count == 0)
{ ChangeLanguageCombo.Items.Add(LocalizationManager.SupportedLanguages.En);
ChangeLanguageCombo.Items.Add(LocalizationManager.SupportedLanguages.Bn);
}
SelectChoice();
}
private void ButtonSaveLang_OnClick(object sender, RoutedEventArgs e)
{
//Store the Messagebox result in result variable
MessageBoxResult result = MessageBox.Show("App language will be changed. Do you want to continue?", "Apply Changes", MessageBoxButton.OKCancel);
//check if user clicked on ok
if (result == MessageBoxResult.OK)
{
var languageComboBox = ChangeLanguageCombo.SelectedItem;
LocalizationManager.ChangeAppLanguage(languageComboBox.ToString());
//Application.Current.Terminate(); I am commenting out because I don't neede to restart my app anymore.
}
else
{
SelectChoice();
}
}
private void SelectChoice()
{
//Select the saved language
string lang = LocalizationManager.GetCurrentAppLang();
if(lang == "bn-BD")
ChangeLanguageCombo.SelectedItem = ChangeLanguageCombo.Items[1];
else
{
ChangeLanguageCombo.SelectedItem = ChangeLanguageCombo.Items[0];
}
}
}
***Note: Before understanding what I did on LanguageSettings page's code behind, you must implement the codes from the link as stated earlier. And also it may be noted that I am working on windows phone 8
I created my WPF single instance app by using the Microsoft.VisualBasic dll method. However I'm facing some difficulty to get the file path for second clicked file which associated with my app.
For example, I have two file "First.my" and "Second.my". When I click on file "First.my" it will launch my app and pop up message box to show "First.my" file path. Since my app is single instance app, when I click on file "Second.my" it should show the file path for "Second.my" but it still showing the file path for "First.my"..
Does anyone know how to pass the associate file path in single instance app?
Below is my code:
class WindowsFormsApp : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
private App _wpfApp;
public WindowsFormsApp()
{
IsSingleInstance = true;
}
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
MessageBox.Show("First File");
//Get 1st click file path
GetFilePath();
_wpfApp = new App();
_wpfApp.Run();
return false;
}
protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs e)
{
MessageBox.Show("Second File");
//Get 2nd click file path
GetFilePath();
}
protected void GetFilePath()
{
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
{
var filePath = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
var uri = new Uri(filePath);
MessageBox.Show(uri.LocalPath);
}
}
}