Add dropdown to settings charm in Windows 8 Metro (C#) - windows-8

I found how can I add command (looks like link) to settings charm:
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
var cmd = new SettingsCommand("feedback", "Send feedback", new Windows.UI.Popups.UICommandInvokedHandler(x =>
{
App.ShowSendFeedback();
}));
args.Request.ApplicationCommands.Clear();
args.Request.ApplicationCommands.Add(cmd);
}
Now I need adding dropdown list for language selection to settings charm. How can I achieve it?

See also this blog post, which explains how you can display a custom user control whenever one of your settings are selected.
Basically, he moves an off-screen user control on-screen and then hides it again when user interaction is done. To me this feels kind of hack-ish... But I guess that's where WinRT is right now.

You can't add it directly to the Win8 UI. The idea is to publish 'command' links into the Win8 UI and then, when they are clicked, your app gets notified. At that point, you show your own UI with whatever widgets you want in it. See any of the Settings samples in the SDK for an example.

Related

Is it possible to add a progress bar to the taskbar icon of a Windows Forms App? [duplicate]

Windows 7 has an AWESOME new feature that applications can report the progress of the current activity through the status bar. For example, when copying file(s) using Windows Explorer, a progress bar is layered on top of the application icon in the task bar and the progress is shown as it updates.
What is the API for exposing the progress bar? Is there MSDN documentation on it?
For below .NET 4, or WinForms in any .NET version
Using the Windows API Code Pack from Microsoft (as Keeron mentioned), it's really simple. You just need to use the TaskbarManager. E.g.
To start the progress:
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
To update the progress:
TaskbarManager.Instance.SetProgressValue(currentValue, maxProgressValue);
And when when you're done, to end the progress:
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
There is more you can do, but that should get you started and might be all you need.
For .NET 4 and above with WPF
You can use System.Windows.Shell.TaskbarItemInfo. E.g. in the Xaml for your main window, you'll need to add:
<Window.TaskbarItemInfo>
<TaskbarItemInfo x:Name="taskBarItemInfo" />
</Window.TaskbarItemInfo>
Then to update the progress, you would do something like:
taskBarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
for (int i = 0; i < 100; i++)
{
taskBarItemInfo.ProgressValue = i / 100.0;
Thread.Sleep(50); // whatever the 'work' really is
}
taskBarItemInfo.ProgressState = TaskbarItemProgressState.None;
Don't forget that if you're doing the 'work' on a background thread (which is probably a good idea for long running tasks), you will need to switch back to the UI thread to update the taskbar.
There's a good article in MSDN magazine about the new taskbar APIs. And yes, the feature is awesome :-)
Essentially, it's all about implementing IFileOperation. There's a good article about using it in managed code here.
If you plan to use other Windows 7 Taskbar features, another approach would be to use the library from Microsoft: Windows API Code Pack for .NET Framework which is no longer available at the old link, but can be found on nuget.
I've written an article about implementing the Windows 7 Taskbar progress API in C# (see: Windows 7 Taskbar Progress Bar with C# and .NET). The control is open source (BSD) and has example projects for C# and VB.NET.
This way you don't have to convert the C++ code from scratch.
Actually I use Telerik's RadWindow which you cannot just use <telerik:RadWindow.TaskbarItemInfo>. So I use this workaround for net6.0-windows WPF:
In code behind file I made a property:
public Lazy<TaskbarItemInfo> TaskbarItemInfo { get; set; } = new Lazy<TaskbarItemInfo>(() =>
{
return System.Windows.Application.Current.MainWindow.TaskbarItemInfo = new TaskbarItemInfo();
});
In method part of BackgroundWorker
private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e)
I set the value of the progress:
TaskbarItemInfo.Value.ProgressState = TaskbarItemProgressState.Normal;
TaskbarItemInfo.Value.ProgressValue = (double)progressUserState.ProgressInPercent / 100;
In
private void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
I reset the state:
TaskbarItemInfo.Value.ProgressValue = 0;
TaskbarItemInfo.Value.ProgressState = TaskbarItemProgressState.None;

Changing language in UWP doesn't change system features language - only on app restart

I have a UWP application.
And i have a need to change locale on the fly, so i have this for language changing:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language.FourDigitCode;
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();
But there is a problem that system features language doesn't switch ( only after application relaunch ) how can i fix it?
Here is an example:
Now i run this code:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "lv-LV";
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();
The UI gets localized, but system features still remain unlocalized:
But when i restart the app, all is OK:
Any ideas how can i fix it?
I'm afraid there is no fix for this and what you've seen is by design. Ref Remarks of PrimaryLanguageOverride property:
When you set the PrimaryLanguageOverride, this is immediately reflected in the Languages property. However, this change may not take effect immediately on resources loaded in the app UI. To make sure the app responds to such changes, you can listen to the QualifierValues property on a default resource context and take whatever actions may be needed to reload resources. Those requirements may vary depending on the UI framework used by the app, and it may be necessary to restart the app.
For your scenario, a restart is needed. I'd suggest that you can add a tip to tell users to restart the app and also a button to close the app like what used in News App.
And to close the app, we can call Application.Exit method like the following.
Application.Current.Exit();
Maybe page reloading can fix it? Try to re-navigate to the same page.
Found the example below here.
//like this
private bool Reload(object param = null)
{
var type = Frame.CurrentSourcePageType;
Frame.Navigate(type, param);
Frame.BackStack.Remove(Frame.BackStack.Last());
}
// or like this
private bool Reload(object param = null)
{
var frame = Window.Current.Content as Frame;
frame.Navigate(frame.CurrentSourcePageType, param);
frame.BackStack.Remove(frame .BackStack.Last());
}

How do I add my privacy policy link to the Windows Settings charm with Unity?

Windows Store rule 4.1.1 mandate that:
You must provide access to your privacy policy in the Description page
of your app, as well as in the app’s settings as displayed in the
Windows Settings charm.
The Description page is easy, since when you setup your app in the store there's a field where you can enter the URL.
However I'm a bit clueless about how to add this entry in the Windows Setting charm in a Unity project. I've found this answer but that assumes you are in full control and knowledge of your Windows Store app, while I'm just exporting from Unity, so I've no clue on where I would put that code.
So, how do I do that?
Unity is exporting the game as JS or C#.
So have a look to these samples http://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-Samples. In these samples, there are a few Setting Charm screnios that you can use in your application.
But remember that, you should add setting charm after export the game.
The plugin prime31/MetroEssentials has the function registerSettingsCommand, which allows you to do just that.
// Registers a settings item with an associated message that will be displaed in a popup when clicked
public static void registerSettingsCommand( string title, string message )
// Registers a settings item with an action. When the settings item is clicked the action will be called.
public static void registerSettingsCommand( string title, Action onActivated )

App works as desired in debug mode but crashes in Rally environment

I have created an app that creates a grid dynamically, as well as lets the user make changes to one of the grid columns via a 'numberfield' editor. Everything is working great in the debug environment but when I try to edit one of the fields in the Rally environment it crashes the app. From the looks of it, the iframe containing the app is just reloading altogether.
Now, here's the weird part that may be a clue to what's going on. The app crashes after I click elsewhere on the app (committing the change) but if I scroll the mouse wheel somewhere on the app, the spinner loses focus (no up/down arrows) and then if I click somewhere the edits are applied and the app doesn't crash. Once again in the debug mode I don't need to go through this, I can just click elsewhere and the changes are applied.
This is a known issue with 2.0p5 that will be fixed with the next release of the SDK. Basically it's using a sledgehammer to respond to the fact that something was edited and refreshing it. Since the new SDK can communicate with the message bus this is totally unnecessary...
In the meantime you should be able to patch your app by defining a global Rally.getApp function that returns your app instance to prevent the hard refresh:
//In your app definition give it an xtype:
Ext.define('My.App', {
extend: 'Rally.app.App',
//...
alias: 'widget.myapp'
//...
});
//Find the app instance by its xtype and return it
Rally.getApp = function() {
return Ext.ComponentQuery.query('myapp')[0];
};
You can then delete that code once 2.0p6 is released and you upgrade.

Microsoft AdControl stealing focus - Windows 8 MonoGame

I am currently writing a simple snake clone game for Windows 8 using MonoGame. I am using the XAML - MonoGame template and trying to include advertising support. I have found an issue, pretty sure it's with the AdControl itself, not MonoGame, however it is stealing keyboard focus every time an ad is loaded.
I have tried to reinitialize the MonoGame 'MetroGameWindow' instance to try and get focus back with no luck. Eg,
void GamePage_LostFocus(object sender, RoutedEventArgs e)
{
MetroGameWindow.Instance.Initialize(Window.Current.CoreWindow,this)
// 'this' is 'GamePage' which inherits from 'SwapChainBackgroundPanel'
}
Does any one know any workarounds for this problem? Any help would be appreciated.
This ia a known problem with AdControl. As of now best solution is to set IsEnabled property of AdControl to false. Doing so will prevent AdControl from taking focus on ad reloads while remaining clickable. See following discussion on bing ads forum: http://community.bingads.microsoft.com/ads/en/publisher/f/63/t/73548.aspx