At the moment,my app have many window with correspond ID..Each I want to go to other page,I create a window and add view corresspond and open it.
I want to manage windows by stack array.
Each create a new window and open it, I will push ID of that window to stack windows.Then operate test in stack array..If that ID existed,I will close window in front of with that ID.
The code is follow:
var stackWindows=[]; //global variable
//function test the exist of window
function testWindowExist(windows)
{
for(var i=0;i<windows.length;i++)
{
for(var j=i+1;j<windows.length;j++)
{
if(windows[i]==windows[j])
{
return windows[i];
//close windows with ID=windows[i];
}
else
{
//do nothing
return 0;
}
}
}
}
I think I can get ID of windows existed but I don't know the way to close that window.
Can you help me.(Sorry,I am not good at English)
Closing a window is really easy:
windows[i].close();
But you've got bigger issues than that, I believe. Your algorithm above is identical to this one:
if (windows.length < 2) return undefined;
if (windows[0] == windows[1] return windows[0];
return 0;
Related
I am developing a UWP windows 10 application and I want to have a page that is only shown at the start of launching application first time. It should not be shown when the app is opened second time in a system.
I have searched online about it but couldn't find any thing about it.
I know that my answer can be refined more, but i have done with spending 2 minutes and its working for me. I have added a page loaded event in my StartPage.xaml.cs file and added the following code inside it.
if (localSettings.Values["IsFirstTime"] == null)
{
localSettings.Values["IsFirstTime"] = true;
}
if ((bool)localSettings.Values["IsFirstTime"])
{
localSettings.Values["IsFirstTime"] = false;
this.Frame.Navigate(typeof(MainPage));
}
Make sure you make a localSettings object at class level (of type ApplicationDataContainer). Now inside App.xaml.cs, I have added global variable for local settings as follow.
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Inside app.xaml.cs file come to the if condition showing rootFrame.Content == null and replace every thing inside it with the following code.
object value = localSettings.Values["IsFirstTime"];
if (localSettings.Values["IsFirstTime"] != null)
{
if ((bool)value)
{
rootFrame.Navigate(typeof(StartPage), e.Arguments);
localSettings.Values["IsFirstTime"] = false;
}
else
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
}
else
{
rootFrame.Navigate(typeof(StartPage), e.Arguments);
localSettings.Values["IsFirstTime"] = false;
}
I have tried it by uninstalling my app and run again to see if start page is shown (and it shows up). Second time when i open, MainPage is shown).
In App.xaml.cs look for the OnLaunched handler. There are these lines of code for "switching" pages:
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
As #Romasz suggested in comments, you can add here additional logic with local (or better - roaming) storage to check whether app is launched for the first time:
var roamingSettings = ApplicationData.Current.RoamingSettings;
if (roamingSettings.Values.ContainsKey("NotFirstTimeLaunch"))
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
} else
{
roamingSettings.Values["NotFirstTimeLaunch"] = true;
rootFrame.Navigate(typeof(FirstLaunchPage), e.Arguments);
}
Update: It appears that the fix for bug 967982 is what's causing this. It would still be great to know either (a) how to work around this or (b) if there's an alternative way to find text in a given page.
One of my Firefox extensions programmatically uses the browser's find bar to locate text on a web page. In recent versions of Firefox, executing my add-ons code causes the find bar to appear when a search term is not found, something it didn't do previously. My routine looks like this:
// Reuse the find bar mechanisms in Firefox (we get a bunch of stuff for free that way)
FindInPage: function(term, e) {
var findBar = document.defaultView.gFindBar;
var shiftKey = e.shiftKey;
var findObj;
var cachedFindTerm;
if ("_find" in findBar) {
findObj = {
find: function(t) {
findBar._find(findBar._findField.value = t);
},
findNext: function() {
findBar._findAgain(false);
},
findPrevious: function() {
findBar._findAgain(true);
}
};
cachedFindTerm = gFindBar._findField.value;
} else {
findObj = findBar;
cachedFindTerm = getBrowser().findString;
}
if (cachedFindTerm == term) {
if(shiftKey)
findObj.findPrevious();
else
findObj.findNext();
} else {
findObj.find(term);
if(shiftKey)
findObj.findPrevious();
}
},
Is there some way I can prevent the find bar from appearing when this block gets executed? I'm aware that using private functions like this is not a best practice, but is there a better way to find a given word in a web page? Some sort of search API available to add-on authors that I'm not aware of?
Im working on a MVVM Windows phone app that displays weather info.
When the app loads up it opens MainPage.xaml. It makes a call the the service to get weather info and binds that data to the UI. Both Fahrenheit and Celcius info are returned but only one is displayed.
On the setting page, the user can select to view the temp in either Fahrenheit or Celcius.
The user can change this setting at any time and its stored in IsolatedStorageSettings.
The issue Im having is this:
when the user navigates to the Settings page and changes their preference for either Fahrenheit or Celcius, this change is not reflected on the main page.
This issue started me thinking about this in a broader context. I can see this being an issue in ANY MVVM app where the display depends on some setting in IsolatedStorage. Any time any setting in the IsoStore is updated, how does the ViewModels know this? When I navigate back in the NavigationStack from the settings page back to MainPage how can I force a rebind of the page?
The data in my model hasnt changed, only the data that I want to display has changed.
Am I missing something simple here?
Thanks in advance.
Alex
Probably you have code like this:
public double DisplayTemperature
{
get { return (IsCelsium) ? Celsium : Fahrenheit; }
}
And IsCelsium is:
public double IsCelsium
{
get { return (bool)settings["IsCelsium"]; }
set { settings["IsCelsium"] = value; }
}
So you need to add NotifyPropertyChanged event to notify UI to get new values from DisplayTemperature property:
public double IsCelsium
{
get { return (bool)settings["IsCelsium"]; }
set
{
settings["IsCelsium"] = value;
NotifyPropertyChanged("DisplayTemperature");
}
}
Take a look at Caliburn Micro. You could implement something similar or use CM itself. When using CM I don't even think about this stuff, CM makes it so simple.
When your ViewModel inherits from Screen there are life-cycle events that fire that you can override. For example, OnInitialize fires the very first time the ViewModel is Activated and OnActivate fires every time the VM is activated. There's also OnViewAttached and OnViewLoaded.
These methods are the perfect place to put logic to populate or re-populate data.
CM also has some special built in features for allowing one to easily tombstone a single property or an entire object graph into Iso or phone state.
ok, so Ive come up with a solution. Before I get to it, let me provide some background. The app that Im working on uses both MVVM Light and WP7Contrib. That being the case, I am using Funq for DI and the MVVMLight Toolkit. After I posted my initial question, I gave the question a bit more thought. I remembered a video that I watched a while back from MIX2011 called Deep Dive MVVM with Laurent Bugnion
http://channel9.msdn.com/Events/MIX/MIX11/OPN03
In it, he talks about just this problem (view models not living at the same time) on Windows Phone. The part in question starts around the 19 minute mark.
Anyway, after I remembered that and realized that the ViewModel locator is exposed in App.xaml, this became a trivial problem to solve. When the user changes the Fahrenheit/Celcius option on the setting page, I simply get a reference to the MainViewModel via the ViewModelLocator and reset the collection that is bound to the UI thus causing the bindings to update.
public bool AddOrUpdateValue(string Key, Object value)
{
bool valueChanged = false;
// If the key exists
if (settings.Contains(Key))
{
// If the value has changed
if (settings[Key] != value)
{
// Store the new value
settings[Key] = value;
valueChanged = true;
}
}
// Otherwise create the key.
else
{
settings.Add(Key, value);
valueChanged = true;
}
return valueChanged;
}
public bool ImperialSetting
{
get
{
return GetValueOrDefault<bool>(ImperialSettingKeyName, ImperialSettingDefault);
}
set
{
if (AddOrUpdateValue(ImperialSettingKeyName, value))
{
Save();
RaisePropertyChanged("ImperialSettingText");
var vml = new ViewModelLocator();
vml.MainViewModel.Cities = (App.Current as App).Cities;
}
}
}
It was a mistake on my part not to realize that I could get access to the viewModel via the ViewModelLocator. Hopefully this post saves someone else the time I burned on this issue.
i have 2 tframes, and an add button. I am trying to add one tframe onto the other when the button is press. but for w.e reason my code can't seem to work. it's not adding the frame like it's suppose to. there is no errors or running, it compiles and runs, but when i press the button it does nothing. i got it to work when i added a tframe to a scrollbox, and all i did was change the location for the tframe to be added.
code for TFrame2
void __fastcall TFrame2::AddFrame()
{
int temp = 0;
TFrame1* NewFrame1 = new TFrame1(this);
NewFrame1 ->Parent=this;
TComponentEnumerator * ParentEnum = GetEnumerator();
while(ParentEnum->MoveNext())
{
temp++;
}
NewFrame1 ->SetIndex(temp);
NewFrame1 ->Name = "Frame" + IntToStr(temp);
NewFrame1 ->Top = ( NewFrame1 ->Height ) * (temp);
}
this is the code i use for TFrame1 itself
void __fastcall TFrame1 ::SetIndex(int temp)
{
this->temp= temp;
}
int __fastcall TFrame1 ::GetIndex()
{
return this->temp;
}
a lil bg info: the reason i have to add tframe to another tframe, is so i can add a group of components onto another group of components, i didn't know any other way to do it. later on i add tframe2 onto the main form.
Given the code you have shown, the only thing that could be going wrong is if you are setting the child frame's Top property to a value that exceeds the Height property of its parent frame so that you would not see the child frame appear onscreen even though it does exist in memory.
How can I create a confirm dialog in windows phone 7?
I have an app in which I can delete items, but when someone clicks delete, I want to get him a confirm dialog where they can click 'confirm' or 'abort'
How could I do this?
you can use this:
if(MessageBox.Show("Are you sure?","Delete Item", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
//Delete Sentences
}
Shows a dialog something like this:
Here is the method I use. By the way for a better user experience and for consistencies sake consider using the words "delete" and "cancel" rather than "confirm" or "abort".
public static MessagePromptResult Show(string messageBoxText, string caption, string button1, string button2)
{
int? returned = null;
using (var mre = new System.Threading.ManualResetEvent(false))
{
string[] buttons;
if (button2 == null)
buttons = new string[] { button1 };
else
buttons = new string[] { button1, button2 };
Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox(
caption,
messageBoxText,
buttons,
0, // can choose which button has the focus
Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, // can play sounds
result =>
{
returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result);
mre.Set(); // could have done it all without blocking
}, null);
mre.WaitOne();
}
if (!returned.HasValue)
return MessagePromptResult.None;
else if (returned == 0)
return MessagePromptResult.Button1;
else if (returned == 1)
return MessagePromptResult.Button2;
else
return MessagePromptResult.None;
}
You will need to add a reference to Microsoft.Xna.Framework.GamerServices to your project.
Rather than asking the user to confirm deletion, have you considered giving the user the ability to "un-delete" items?
While this may be a little bit more work, when it makes sense in teh context of the app it can lead to a much better user experience.
If OK / Cancel is good enough for you, you could stick to the regular MessageBox.Show