/// <summary> /// Adds secondary tile /// </summary> private async void AddSecondaryTileAsync() { Uri square150x150Logo = new Uri("ms-appx:///Assets/square150x150Tile-sdk.png"); string tileActivationArguments = "SelectedImage=" + PhotoListBox.SelectedIndex; string selectedItem = PhotoListBox.SelectedItem.ToString(); char[] delimiterChars = { '\\' }; string[] words = selectedItem.Split(delimiterChars); SecondaryTile tile = new SecondaryTile("SecondaryTileId" + PhotoListBox.SelectedIndex, words[(words.Length - 1)], tileActivationArguments, square150x150Logo, TileSize.Default); IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)tile; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); // The display of the secondary tile name can be controlled for each tile size. // The default is false. tile.VisualElements.ShowNameOnSquare150x150Logo = true; // Specify a foreground text value. // The tile background color is inherited from the parent unless a separate value is specified. tile.VisualElements.ForegroundText = ForegroundText.Light; await tile.RequestCreateAsync(); }
public MainWindow() { this.InitializeComponent(); Button button2 = new() { Content = "created dynamically" }; button2.Click += async(sender, e) => { // TODO: change to (with version 0.8): // await new MessageDialog("button 2 clicked").ShowAsync(); MessageDialog dlg = new("button 2 clicked"); IInitializeWithWindow withWindow = dlg.As <IInitializeWithWindow>(); var handle = this.As <IWindowNative>().WindowHandle; try { withWindow.Initialize(handle); await dlg.ShowAsync(); } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } }; stackPanel1.Children.Add(button2); list1.Items.Add(new Person() { FirstName = "Stephanie", LastName = "Nagel" }); }
private async void FileErrorAttachment_Click(object sender, RoutedEventArgs e) { // Open a text file. FileOpenPicker open = new FileOpenPicker(); open.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; open.FileTypeFilter.Add("*"); // When running on win32, FileOpenPicker needs to know the top-level hwnd via IInitializeWithWindow::Initialize. if (Window.Current == null) { IInitializeWithWindow initializeWithWindowWrapper = open.As <IInitializeWithWindow>(); IntPtr hwnd = GetActiveWindow(); initializeWithWindowWrapper.Initialize(hwnd); } StorageFile file = await open.PickSingleFileAsync(); var filePath = string.Empty; if (file != null) { filePath = file.Path; FileAttachmentLabel.Text = filePath; } else { FileAttachmentLabel.Text = "The file isn't selected"; } localSettings.Values[Constants.KeyFileErrorAttachments] = filePath; }
private void InitializeActiveWindow(ICustomQueryInterface picker) { IInitializeWithWindow initializeWithWindowWrapper = picker.As <IInitializeWithWindow>(); IntPtr hwnd = GetActiveWindow(); initializeWithWindowWrapper.Initialize(hwnd); }
private async Task PinToStart() { try { // Initialize the tile with required arguments SecondaryTile tile = new SecondaryTile( "myTileId5391", "Display name", "myActivationArgs", new Uri("ms-appx:///Images/Square150x150Logo.png"), TileSize.Default); // Assign the window handle IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)tile; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); // Pin the tile bool isPinned = await tile.RequestCreateAsync(); // TODO: Update UI to reflect whether user can now either unpin or pin } catch (Exception ex) { } }
public static void InitializeWithWindow(Object obj) { // When running on win32, FileOpenPicker needs to know the top-level hwnd via IInitializeWithWindow::Initialize. if (Window.Current == null) { IInitializeWithWindow initializeWithWindowWrapper = obj.As <IInitializeWithWindow>(); IntPtr hwnd = GetActiveWindow(); initializeWithWindowWrapper.Initialize(hwnd); } }
public static void Initialize(this MessageDialog md, Window window = null) { IInitializeWithWindow initializeWithWindowWrapper = md.As <IInitializeWithWindow>(); IntPtr hwnd; if (window == null) { hwnd = PInvoke.User32.GetActiveWindow(); } else { hwnd = window.As <IWindowNative>().WindowHandle; }; initializeWithWindowWrapper.Initialize(hwnd); }
public static void Initialize(this MessageDialog md, IntPtr hWndArg) { IInitializeWithWindow initializeWithWindowWrapper = md.As <IInitializeWithWindow>(); IntPtr hwnd; if (hWndArg == IntPtr.Zero) { hwnd = PInvoke.User32.GetActiveWindow(); } else { hwnd = hWndArg; } initializeWithWindowWrapper.Initialize(hwnd); }
/// <summary> /// Launch the Store UI for purchasing the requested store-managed consumable /// </summary> /// <param name="product">The StoreProduct to purchase.</param> /// <returns></returns> public async Task <StorePurchaseResult> PurchaseConsumable(StoreProduct product) { // The next two lines are only required because this is a non-universal app // so we have to initialize the store context with the main window handle // manually. This happens automatically in a Universal app. IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); var result = await storeContext.RequestPurchaseAsync(product.StoreId); if (result.Status == StorePurchaseStatus.Succeeded) { Balance += product.Price.FormattedBasePrice.AsDouble(); } return(result); }
private async void OnButtonClick(object sender, RoutedEventArgs e) { // TODO: this change is not working with 1.0 - with a future version? // await new MessageDialog("button 1 clicked").ShowAsync(); MessageDialog dlg = new("button 1 clicked"); IInitializeWithWindow withWindow = dlg.As <IInitializeWithWindow>(); var handle = this.As <IWindowNative>().WindowHandle; try { withWindow.Initialize(handle); await dlg.ShowAsync(); } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } }
//[DllExport(CallingConvention.StdCall)] public static async Task <bool> _PurchaseAsync(string storeID) { IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext; var ptr = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; initWindow.Initialize(ptr); MessageBox.Show("句柄为" + ptr); MessageBox.Show("Thread id 2: " + Thread.CurrentThread.ManagedThreadId); var result = await storeContext.RequestPurchaseAsync(storeID).AsTask().ConfigureAwait(false); if (result.ExtendedError != null) { MessageBox.Show(result.ExtendedError.Message, result.ExtendedError.HResult.ToString()); } switch (result.Status) { case StorePurchaseStatus.Succeeded: break; case StorePurchaseStatus.AlreadyPurchased: break; case StorePurchaseStatus.NotPurchased: break; case StorePurchaseStatus.NetworkError: break; case StorePurchaseStatus.ServerError: break; default: break; } MessageBox.Show("Purchase Finished with status " + result.Status); return(true); }
public async Task <string?> BrowseFolderAsync() { var picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder, FileTypeFilter = { "*" } }; // TODO: workaround from https://github.com/microsoft/microsoft-ui-xaml/issues/2716#issuecomment-727043010 if (Window.Current == null) { IInitializeWithWindow initializeWithWindowWrapper = picker.As <IInitializeWithWindow>(); IntPtr hwnd = GetActiveWindow(); initializeWithWindowWrapper.Initialize(hwnd); } var folder = await picker.PickSingleFolderAsync(); return(folder?.Path); }
private async void OnIAsyncOperation(object sender, RoutedEventArgs e) { MessageDialog dlg = new("Select One, Two, Or Three", "Sample"); // TODO: remove workaround after next preview? IInitializeWithWindow withWindow = dlg.As <IInitializeWithWindow>(); var handle = this.As <IWindowNative>().WindowHandle; try { dlg.Commands.Add(new UICommand("One", null, 1)); dlg.Commands.Add(new UICommand("Two", null, 2)); dlg.Commands.Add(new UICommand("Three", null, 3)); withWindow.Initialize(handle); IUICommand command = await dlg.ShowAsync(); text1.Text = $"Command {command.Id} with the label {command.Label} invoked"; } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } }
private async Task <Tuple <string, ILanguage> > GetCodeFileText() { try { var picker = new FileOpenPicker(); IntPtr windowHandle = (App.Current as App).WindowHandle; IInitializeWithWindow initializeWithWindowWrapper = picker.As <IInitializeWithWindow>(); initializeWithWindowWrapper.Initialize(windowHandle); picker.FileTypeFilter.Add("*"); var file = await picker.PickSingleFileAsync(); if (file == null) { return(null); } System.Diagnostics.Debugger.Launch(); string text = ""; using (var reader = new StreamReader(await file.OpenStreamForReadAsync(), true)) { text = await reader.ReadToEndAsync(); } ILanguage Language = Languages.FindById(file.FileType.Replace(".", "")) ?? Languages.CSharp; return(new Tuple <string, ILanguage>(text, Language)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(new Tuple <string, ILanguage>("ERROR", Languages.CSharp)); } }
/// <summary> /// The Wvrapper arownd <see cref="IInitializeWithWindow.Initialize(IntPtr)"/> /// </summary> /// <param name="Hwind">The Hwind of the owner Window</param> /// <param name="winRTObj">The WinRT object</param> public static void Initialize(IntPtr Hwind, object winRTObj) { IInitializeWithWindow initWithWindow = (IInitializeWithWindow)(object)winRTObj; initWithWindow.Initialize(Hwind); }
/// <summary> /// WinRT オブジェクトのスレッド モデルとの親和性を設定します /// Initialize Windows Runtime Object. /// </summary> /// <param name="winRT"></param> internal static void InitializeWithWindow(object winRT) { IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)winRT; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); }