Sorry for the mess of a title.
Ive got the following C# script handling an Async Button press:
private async void CalcButton_ClickAsync(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("calculator:"));
}
Issue i have is that the calculator is loading up the exact same size as the main program window. I was wondering if there is a way to over-ride the sizing of the launched windows, i want the calculator to open up as small as possible really.
Come to think of it, i think every popup windows is doing this (save/open file dialogues) any thoughts/suggestions would be amazing
You can request the desired remaining view. Keep in mind that it is specifying the remaining view of the app that is launching the calculator... not the size of the calculator app.
link here
private async void LaunchCalculator(object sender, RoutedEventArgs e)
{
var options = new Windows.System.LauncherOptions();
options.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseMore;
await Windows.System.Launcher.LaunchUriAsync(new Uri("calculator:"), options);
}
Related
I have made a program in WPF previously and am trying to transcirpt it into UWP. However I have come across a barrier.
In WPF you can easily create a new instance of a window and .Show that window
For example:
public static SecondGUI_Window secondGUI = new SecondGUI_Window();
secondGUI.Show();
However in UWP I am still confused as how to create a new window. I have tried doing it the same way as in WPF however it doesn't seem to work. I have also viewed and tried a couple of other answers from other stack overflow's
Second Window - XAML page (UWP app)
To no avail have I been able to get it working yet.
The main reason I want to have the second screen is so that I can display data on another screen.
For example the second window can be moved to another screen if the user has two screens.
I would like to keep as much of the usability/flexibility from WPF instancing as possible. For example being able to access the public variables in the window.
When I try and use the code from the example above it gives me an 'await' error.
Image showing error from visual studio
If you need any extra information please ask and I will try my best to provide any information requested.
Any and every help is greatly appreciated.
From the link provided by quaabaam I have managed to get it working.
From the code in the link I used in my question and some help from you guys I've now managed to have a second window running at the same time.
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(DisplayWindow), null);
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
Making sure I had the async in the method call, the program now opens a second window.
Now I need to make sure I can get the second window working how I want it to without any issues...
I have a program which can show some links (music/video/ etc....).
I want when Clicked on download button, my app send that link to UC Downloader for download. I can open link with Internet Explorer but I want open in UC Downloader.
You can launch an app from your code if you know. From the msdn :
By using the association launching API, your app can automatically launch another app by launching a custom URI. To do this, use the Launcher.LaunchUriAsync(Uri) method from the Launcher object of the Windows.System namespace. For example, the following code launches a fictitious Contoso app to display new products.
Example :
private async void LaunchContosoNewProductsButton_Click(object sender, RoutedEventArgs rea)
{
// Launch URI.
Windows.System.Launcher.LaunchUriAsync(new System.Uri("contoso:NewProducts"));
}
You can find a tutorial here.
Here's how.
Windows.System.Launcher.LaunchUriAsync(new Uri("uc-url:http://www.microsoft.com"));
private async void Button_Click(object sender, RoutedEventArgs e)
{
string uriToLaunch = #"http://www.bing.com";
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
In windows phone 8.1
I need to change the BackgroundImage of a button on click of another button (In Windows Forms in C#). But I can't find out how to do it!!
I searched on the internet and found many examples and all of them use ImageBrush, ImageSource etc.... but these don't work on my application, it shows me errors every time I Use them.
I read on the internet that I have to add this namespace:
using Windows.UI.Xaml.Media.Imaging;
But it shows me an error on the begging which says to add this System before Windwons and when I add it:
using System.Windows.UI.Xaml.Media.Imaging;
it shows me than the error at UI .... I can't figure it out how to solve this!!
Please help me guys!
To Change Background Image of a button there are two ways i know.
Add the Image to the resources folder of your project and use.
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Properties.Resources.ImageName;
}
Use Image.FromFile();
private void button2_Click(object sender, EventArgs e)
{
button1.BackgroundImage = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "//Card1.png");
}
You are trying to use solutions for WPF in Winforms. This will not work.
The class you need is System.Drawing.Image (or System.Drawing.Bitmap, which inherits from Image).
Bitmap b = new Bitmap(#"C:\myBitmap.jpg");
myButton.Image = b;
Be sure to call Dispose on your Bitmap if and when it is no longer in use.
I have a project that I'm doing with
Microsoft VSTO (office 2013 excel)
I have certain things that make calls that take maybe 10 seconds to come back.
Ideally I would like to display an progress bar or some status... After a lot of searching I found an article that is titled:
How do I create a splash screen window for the VSTO applications?
http://www.datazx.cn/Fv7p5a/xw/oa2v/2q7xs6/mcccjfti-988m-f8r8-8d44-bstb4rfsi4xm23rsdfd.html
So I started creating this code in a form, but then I realize that I need to call it up within my methods and really attach events etc...
The article says to
"display a modal form on a background thread" What is the best way to do this?
I find it easier to use modal less form on main thread and so far haven't seen any problem with modal less approach. Something like code below
var splashWindow = new SplashWindow();
splashWindow.Show();
splashWindow.SetMessage("Starting please wait...");
DoSomeWork(splashWindow);
splashWindow.Close();
Following you will see a way I programmed a Splash Screen for Excel-VSTO in C#. My Excel file is enabled for macros (.xlsm). These are the steps:
Create your splash screen. Let's assume the name of the form is SplashScreen.
Go to the code of the object ThisWorkbook.cs
Check the code looks like:
public partial class ThisWorkbook
{
SplashScreen SC = new SplashScreen();
private async void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
SC.Show();
await Task.Delay(3500);
SC.Close();
more code...
}
}
It is important that you notice that I added the word async to the subroutine.
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
I hope this is very useful.
My Silverlight application has multiple XAML pages. For example, one displays a clock, one displays a timer. I have buttons to switch back and forth like so:
private void switchRight(object sender, RoutedEventArgs e)
{
this.Content = new Clock();
}
private void switchLeft(object sender, RoutedEventArgs e)
{
this.Content = new Timer();
}
I am trying to use the NavigationService to switch back and forth so I can have other pages running in the background rather than creating a new instance each time.
I am trying
NavigationService.Navigate(new uri("/Timer.xaml", UriKind.Relative));
but it doesn't seem to do anything and I can't find any good examples to help.
Here is a link
http://blogs.msdn.com/b/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx ,
Beside, I think you can use Threading for background processes.i.e.when you start a timer no need to show any xaml.
But for page instances you need to manage it very carefully otherwise stackoverflow :)
Depending on business rules its hard to decide navigation as being in a web browser.
We created our own Wizard (with rules). You may create your own NavigationManager. For validation I can offer http://fluentvalidation.codeplex.com/