Checkbox uncheck for windows 8.1 phone app - checkbox

I have a control checkbox that allows the app to play sounds (SoundEnableBox) when it is checked. If they uncheck it I want it to stay unchecked (So I need to programmadigally uncheck the box when the page is reloaded. The default is set to checked. Every time the page is reloaded it gets checked again.
I tried the following code but it is not working. Do I need to bind the property? to keep it unchecked?
if (GlobalVariables.SoundsEnabled.GlobalBool == false)
{
SoundsEnabledBox.Unchecked = true;
}
I know this should be simple but not with windows phone for some reason.

After looking at this for a short while I decided to change the default to unchecked and wrote the following logic to correct the issue I was having.
if (GlobalVariables.SoundsEnabled.GlobalBool == false)
{
SoundsEnabledBox.IsChecked = false;
}
else if (GlobalVariables.SoundsEnabled.GlobalBool == true)
{
SoundsEnabledBox.IsChecked = true;
}

Related

How to choose from two different webdriver buttons for testing

I am new to webdrivers and I am having the system choose whether it is a create or save button for two different scenarios and differentiate by the ids.
So far I have
var createButton = webDriverConfig.getWebDriver().findElement(By.id(createButtonId));
var jsExecutor = ((JavascriptExecutor) webDriverConfig.getWebDriver());
if(createButton.getText().equals("//button[#title='Create']")) {
jsExecutor.executeScript("arguments[0].scrollIntoView();", createButton);
createButton.click();
} else {
var saveButton = webDriverConfig.getWebDriver().findElement(By.id(saveButtonId));
jsExecutor.executeScript("arguments[0].scrollIntoView();", saveButton);
saveButton.click();
}
However when I ran the system it fails and I am not sure how it can differentiate whether it is a create scenario vs update scenario to save when it clicks the button when it finishes filling out the form.

C# checkedlistbox differentiate between ItemCheck via code and mouse click

I'm using C# VS2008, WinForm application
I have a checkedlistbox control on my form (win-form application)
In the code I check some items in checkedlistbox using the SetItemChecked(index, false) method and it raise the event ItemCheck.
I also allow the user to check items in that checkedlistbox and it also raise the event ItemCheck when the user check or uncheck an item.
How can I find in the ItemCheck event how this event occur (via code or via user keyboard/mouse input)?
Thanks.
I think that there is no a simple way to differentiate the situation using code.
The only thing that comes to mind is through the use of a global form variable:
public class Form1:Form
{
bool _isCodeClick = false;
.....
// Somewhere in your code
_isCodeClick = true;
checkedListBox1.SetItemChecked(index, true);
_isCodeClick = false;
.....
private void CheckedListBox1_ItemCheck(Object sender, ItemCheckEventArgs e)
{
if(_isCodeClick == true)
{
// Do processing for click by code
}
else
{
// Do processing for click by user
}
}
}
If you go for this solution remember to take additional steps to correctly trap exceptions that could bypass the reset of the global variable to the false state.
Probably using advanced manipulation of keyboard and mouse events you could reach a reasonable way to identify what has caused the ItemCheck event, but sometime some solutions are too complex and not worth it.
EDIT: Reviewing my answer I feel the need to add a little change to reduce the maintaining problems that this esponse implies.
The code that set the boolean variable and call the SetItemChecked should be encapsulated in a separate function like this
private void SetItemCheckedFromCode(int index, bool toSet)
{
try
{
_isCodeClick = true;
checkedListBox1.SetItemChecked(index, true);
}
finally
{
_isCodeClick = false;
}
}

Launch default web browser, but not if URL already open

I have a link on my app UI that launches a URL using System.Diagnostics.Process.Start(). If the user clicks the link several times, it opens several tabs.
Is there a way, maybe a command-line option, to still use the default web browser, but have it just reopen the same tab if the URL is already open? It would be OK if it doesn't work with every possible browser out there, but nice if it at least works with IE, Firefox and Chrome.
I doubt it, but since I didn't see any other questions/answers on this topic, I figured I'd ask.
This is somewhat of a workaround but it might get you started. I have used the System.Diagnostics.Process.ProcessId.
As an example I have used IE, I will explain later why I did this. The code is just "quick and dirty" but I just made it as proof of concept.
I have created a basic WinForm app with one button that will open google in IE, if it has already been opened by the application it will not be opened again.
I added the System.Diagnostics reference.
public int ProcessID;
public Form1()
{
InitializeComponent();
}
private void MyButton_Click(object sender, EventArgs e)
{
if (ProcessID == null)
{
StartIE();
}
else
{
if (!ProcessIsRunning())
{
StartIE();
}
}
}
private bool ProcessIsRunning()
{
bool ProcessRunning = false;
foreach (Process p in Process.GetProcesses())
{
try
{
if (p.Id == ProcessID)
{
ProcessRunning = true;
}
}
catch { }
}
return ProcessRunning;
}
private void StartIE()
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "iexplore.exe";
proc.StartInfo.Arguments = "http://www.google.be";
proc.Start();
ProcessID = proc.Id;
}
This does not completely do what you requested but it might be a good start. There are a few reasons why I did it this way and what possible options are..
If you would use the url as the Filename, it would indeed open up the webpage in the default browser, it would however not return a processID. This is why the snippet shows usage of IE. (If you would use this option, you could use the System.IO.File.Exists to make sure the desired browser is installed)
If you would like to use this option, you can query the registry to pick up what te default browser is, if you have that you could launch that from the value obtained from the registry. If you then change the process.startinfo.filename to this value, then you will launch the default browser but you will still obtain a processId so this might be the way forward. You can check how to do this over here: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/b200903e-ce69-4bd4-a436-3e20a7632dc4
Showing the internet window if it would already be opened, can be done by using the SetForegroundWindow property. As this is already documented in this article, I did not add it in this snippet.
I hope this helps to get you on your way.

ExtJS 4 - Load Mask giving errors in IE8 and IE9 when used while opening a window

I have a window which opens up on a button click. The window takes time to load and hence I am using load mask in following way:
handler:function(){
var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Loading..."});
myMask.show();
var winAppln = showWin(myMask);
if(winAppln){
var task = new Ext.util.DelayedTask(function(){
winAppln.show();
});
task.delay(2000);
}
}
I am hiding the mask object in the afterrender function of window in following way:
afterrender:function(){
if(maskObj){
maskObj.hide();
}
}
The above code works fine in all the browsers, except IE (version 9 and 8).
In IE9 and IE8, there is an error generated as "Invalid Argument" in ext-all-debug.js at line 8682 which is as following
me.dom.style[ELEMENT.normalize(style)] = value;
Could anyone guide that what can be a possible reason behind this.
Also, my main purpose is to cover the lag between the click of button & opening of window, so that user is aware about something is happening. Is there a better way of doing this other then using Load Mask, or could Load Mask be used in some different manner, then as shown above?
Thanks in advance.
PS: I am using ExtJS Version 4.0.7
As per the things found by me so far, this issue is caused when the window has modal:true set.
IE 8 and 9 create a conflict between loadMask and modal:true and throw an error.
A workaround for this is to take off modal:true from the window and set it to true in the afterrender event of window once the loadmask hide function has been called as below:
afterrender:function(){
if(maskObj){
maskObj.hide();
}
this.modal = true;
}
Hope this helps someone looking for the same.
There is a bug in ExtJS4 Ext.LoadMask which is a problem in Internet Explorer 7 and 8.
When showing a loading mask, ExtJs tries to figure out the zIndex of the parent element, then setting the zIndex of the loading mask. In Internet Explorer 7/8 an element could also have set the zIndex "auto". parseInt of the string "auto" is NaN. Setting the zIndex to NaN causes an error in IE7/IE8.
The solution: override LoadMask
Ext.override(Ext.LoadMask, {
setZIndex: function(index) {
var me = this,
owner = me.activeOwner;
if (owner) {
index = parseInt(owner.el.getStyle('zIndex'), 10) + 1;
}
if (!isNaN(index)) {
me.getMaskEl().setStyle('zIndex', index - 1);
return me.mixins.floating.setZIndex.apply(me, arguments);
} else {
return '';
}
}
});
This topic is discussed also in Sencha Forums:
http://www.sencha.com/forum/showthread.php?228673-LoadMask-and-setZIndex-and-NaN
http://www.sencha.com/forum/showthread.php?246839
Give it a try with
Ext.getBody().mask("Loading")
I use this instead of LoadMask just because in ext you can't mask more than one component with dimmed background color, .mask() does the trick. LoadMask is prettier, but has some issues, so .mask could work.

How can I force my busy indicator to display? (WPF)

I've created a busy indicator - basically an animation of a logo spinning. I've added it to a login window and bound the Visibility property to my viewmodel's BusyIndicatorVisibility property.
When I click login, I want the spinner to appear whilst the login happens (it calls a web service to determine whether the login credentials are correct). However, when I set the visibility to visible, then continue with the login, the spinner doesn't appear until the login is complete. In Winforms old fashioned coding I would have added an Application.DoEvents. How can I make the spinner appear in WPF in an MVVM application?
The code is:
private bool Login()
{
BusyIndicatorVisibility = Visibility.Visible;
var result = false;
var status = GetConnectionGenerator().Connect(_model);
if (status == ConnectionStatus.Successful)
{
result = true;
}
else if (status == ConnectionStatus.LoginFailure)
{
ShowError("Login Failed");
Password = "";
}
else
{
ShowError("Unknown User");
}
BusyIndicatorVisibility = Visibility.Collapsed;
return result;
}
You have to make your login async. You can use the BackgroundWorker to do this. Something like:
BusyIndicatorVisibility = Visibility.Visible;
// Disable here also your UI to not allow the user to do things that are not allowed during login-validation
BackgroundWorker bgWorker = new BackgroundWorker() ;
bgWorker.DoWork += (s, e) => {
e.Result=Login(); // Do the login. As an example, I return the login-validation-result over e.Result.
};
bgWorker.RunWorkerCompleted += (s, e) => {
BusyIndicatorVisibility = Visibility.Collapsed;
// Enable here the UI
// You can get the login-result via the e.Result. Make sure to check also the e.Error for errors that happended during the login-operation
};
bgWorker.RunWorkerAsync();
Only for completness: There is the possibility to give the UI the time to refresh before the login takes place. This is done over the dispatcher. However this is a hack and IMO never should be used. But if you're interested in this, you can search StackOverflow for wpf doevents.
You can try to run busy indicar in a separate thread as this article explains: Creating a Busy Indicator in a separate thread in WPF
Or try running the new BusyIndicator from the Extended WPF Toolkit
But I'm pretty sure that you will be out of luck if you don't place the logic in the background thread.
Does your login code run on the UI thread? That might block databinding updates.

Resources