How can I make the AppBar on Windows phone disappears/appear programmatically? - windows-phone-8.1

On Windows phone, I can declare App bar in my page like this:
<Page.BottomAppBar>
<CommandBar>
..
</CommandBar>
</Page.BottomAppBar>
My question is how can I programmatically make that app bar disappear and reappear?
Thank you.

Hence IsOpen property opens/closes the AppBar (shows/hides secondary menu and labels), to hide completely the AppBar, I'm just seting BottomAppBar property to null just after remembering the old bar in variable. Then when I want to return my AppBar, I use that variable, sample code:
CommandBar previousBar;
private void HideBar()
{
previousBar = BottomAppBar as CommandBar;
BottomAppBar = null;
}
private void ShowBar()
{
BottomAppBar = previousBar;
}

You can open and close the app bar programmatically by setting the IsOpen property. You can respond to the app bar being opened or closed by handling the Opened and Closed events.
if (this.BottomAppBar != null)
{
this.BottomAppBar.IsOpen = true;
}

Related

Minimize a resizable JDialog

I'm working on an swing application with a main window (which extends JFrame) from which several child windows can be opened (more than 1 contemporarily).
These windows are all non-modal and resizable.
So far, I implemented these 'child' windows as a JFrame. However, I get a new icon on my Windows taskbar for each opened Window.
I therefore tried to implement these windows as a JDialog with type ModalityType.MODELESS.
Looks OK except that a JDialog has no minimize button.
Is there a way to resolve this?
I.e., I need to create non-modal and resizable child windows that can be minimized.
JInternalFrame is not an option since the main frame is not just a container with a JDesktopPane and child windows should be able to cross the borders of the main window.
For those interested:
Child windows register and unregister themselves on the main window when being opened/closed.
The main window has a menu with a 'Windows' item and child windows are added/removed from that menu upon registration/unregistration.
The user can switch between the various windows by selecting an item within this menu.
I am offering two suggestions.
A. Don't use the close button to get rid of the contents.
B. Set the type of child jframes to be utility.
I think having the JDialog close button destroy data is setting your users up for data loss. I would instead use the close to just hide the window, and then have controls inside of the dialog to cancel/finish/restart.
import java.awt.*;
public class DiFrame{
static JDialog log;
static JFrame ame;
public static void main(String[] args){
JFrame frame = new JFrame("Father of two");
JButton one = new JButton("dialog");
one.addActionListener( evt->{
if(log==null){
log = new JDialog(frame, "dialog child", false);
log.add(new JTextArea("fresh start"));
log.pack();
log.setVisible(true);
} else{
log.setVisible(true);
}
});
JButton two = new JButton("frame");
two.addActionListener( evt->{
if(ame==null){
ame = new JFrame("frame child");
ame.add( new JTextArea("fresh start") );
ame.setType(Window.Type.UTILITY);
ame.pack();
ame.setVisible(true);
} else{
ame.setVisible(true);
}
});
frame.add(one, BorderLayout.NORTH);
frame.add(two, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Click the dialog button and it shows the dialog. Then the text area can be modified. When the dialog is closed it can be re-opened.
Click the frame button and a jframe is shown. ( I actually cannot check if this shows up as a new application because it doesn't on my computer anyways. )

How to keep AutoSuggestBox suggestion box open in Windows Phone 8.1

Using the new AutoSuggestBox control in Windows Phone 8.1 (WinRT XAML), I am trying to keep the suggestion box open all the time -- even after the user clicks a suggestion.
I have no problem starting with the suggestion box open by programmatically setting AutoSuggestBox.IsSuggestionListOpen = true;
Then I hook the SuggestionChosen event like this:
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) {
sender.Text = args.SelectedItem.ToString();
sender.IsSuggestionListOpen = true;
}
But unfortunately the suggestion box still closes after selecting an item, even though I set IsSuggestionListOpen to true.
Any help with getting it to stay open after a selection would be appreciated.
The solution I found to this is to hook the LayoutUpdated event.
I have the AutoSuggestBox in a PickerFlyout, so I only want the suggestion box open if the PickerFlyout is open (obviously). So I set a Tag property on the button that opens the PickerFlyout to identify if the PickerFlyout is open or closed. Then in the LayoutUpdated event of the AutoSuggestBox I set the IsSuggestionListOpen property to true if the PickerFlyout is open (and false if it's not).
The code:
private void PickerFlyout_Opened(object sender, object e) {
ActivatePickerFlyoutButton.Tag = "open";
}
private void PickerFlyout_Closed(object sender, object e) {
ActivatePickerFlyoutButton.Tag = "closed";
}
private void AutoSuggestBox_LayoutUpdated(object sender, object e) {
AutoSuggestBox.IsSuggestionListOpen = ((ActivatePickerFlyoutButton.Tag as string).Equals("open"));
}
That is the only place I need to set the IsSuggestionListOpen property, since the LayoutUpdated event fires at all the right times.

Javafx: setting a Tab mnemonics

Quick question: Is it possible to set a mnemonic for a JavaFX Tab?
I can only seem to be able to set them for such controls as buttons, and menu items.
Okay, this is an interesting question! You are right, you can not set the mnemonic directly on a Tab. But you can add a component as a Tabs graphic that supports the mnemonic feature:
private class MTab extends Tab
{
public MTab(String pText)
{
super();
Button fakeLabel = new Button(pText);
fakeLabel.setMnemonicParsing(true);
fakeLabel.getStyleClass().clear();
setGraphic(fakeLabel);
fakeLabel.setOnAction(ev -> {
if (getTabPane() != null) {
getTabPane().getSelectionModel().select(this);
}
});
}
}
Using this tab:
TabPane tabs = new TabPane();
tabs.getTabs().add(new MTab("_this is a test"));
tabs.getTabs().add(new MTab("t_his is a test"));
tabs.getTabs().add(new MTab("th_is is a test"));
Will make your tabs switchable via shortcuts.

Metro App SuspensionManager Override SaveState Behaviour

How do I modify the SuspensionManager object in a Metro App, to SaveState for the MainPage only and discard State and Navigation for any child pages?
E.g. I have a MainPage that allows you to Navigate to a ChildPage. If the Metro App is Closed or Suspended, I want the ChildPage to override the MainPage state values.
Now, the next time the user opens the app, the MainPage should open and not the ChildPage. Also the MainPage should show State that the ChildPage updated before the app was Closed or Suspended.
Any ideas on how the SuspensionManager object can be safely modified to accomplish this?
Why not just add your data from the ChildPage to the SessionState dictionatry and fill it into the MainPage when the app resumes ?
You don't even need to modify the SuspensionManager for doing that!
public BasicPage1() {
this.InitializeComponent();
Application.Current.Suspending += Current_Suspending;
Application.Current.Resuming += Current_Resuming;
}
void Current_Resuming( object sender, object e ) {
var name = SuspensionManager.SessionState["name"].ToString();
}
void Current_Suspending( object sender, Windows.ApplicationModel.SuspendingEventArgs e ) {
SuspensionManager.SessionState.Add( "name", "danielovich" );
}
Using the suggestion from Danielovich (which is NOT complete), the solution is 2 parts:
Firstly:
No longer save state in the pageState object, instead save state
using the SessionState object. Why? This is so that all Pages can share the same State information.
Secondly:
To ensure, that NavigationState is not saved so that MainPage is always the default page, we need to change the SaveFrameNavigationState in SuspensionManager as follows:
private static void SaveFrameNavigationState(Frame frame)
{
var frameState = SessionStateForFrame(frame);
frame.GetNavigationState();
frameState["Navigation"] = "1,1,0,15,Skycap.MainPage,12,0";
}

Windows Store App launch

I'm having issues with my Windows Store App launch. When I use the "close app gesture" (slide the app from top to bottom) and then launch the app again very fast, sometimes a blank black screen appears and when I click on it, it, the Start menu appears, and a "MoAppHang" event is logged.
My App_Launched event code is here:
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated )
{
// Restore the saved session state only when appropriate
await SuspensionManager.RestoreAsync();
}
// Do not repeat app initialization when already running, just ensure that
// the window is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
if (!string.IsNullOrEmpty(args.Arguments))
{
Frame f = Window.Current.Content as Frame;
if (f != null)
{
UseSecondaryTileNavigation(f, args.Arguments);
}
}
Window.Current.Activate();
return;
}
Frame rootFrame;
if (Window.Current.Content == null)
{
// Create a Frame to act as the navigation context and associate it with
// a SuspensionManager key
rootFrame = new Frame();
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
}
else
{
rootFrame = (Frame)Window.Current.Content;
}
if (!await DatabaseHelper.ExistsDatabase())
{
await DatabaseHelper.CreateDatabase();
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(ItemsPage), "AllGroups"))
{
throw new Exception("Failed to create initial page");
}
}
if (!string.IsNullOrEmpty(args.Arguments))
{
UseSecondaryTileNavigation(rootFrame, args.Arguments);
}
// Place the frame in the current Window and ensure that it is active
if (Window.Current.Content == null)
{
Window.Current.Content = rootFrame;
}
Window.Current.Activate();
The UseSecondaryTileNavigation performs navigation when user opens the app using secondary tile (it basically uses the Frame parameter and Navigates it to the correct location using Frame.Navigate).
Where am I going wrong?
Thank you all!
It looks like you could potentially be doing a bit of time-consuming work in your launch handler. The first suggestion I'd make is to use a custom splash screen technique. That is, in your OnLaunched handler try to set the Window.Current.Content and activate the window and get out of that method ASAP. You could set Window.Current.Content to a page that just shows a loading progress bar - and handle your actual loading logic in there.
The next thing to look at - is what happens when your app is launched while it is still suspending? (Do you have a suspending handler?) Can your app handle the case when it is (re-)launched before a previous suspension / close completes?
I've noticed that it generally seems to take a few seconds before the app is fully closed (even though you close it using the drag down gesture).