ListBoxItem background color - windows-phone-7

I want upon selection to change the background color of the item, however i can't seem to find a way to do it.
I'm trying to use the code below but can't find the completion for it, and i need to set the colror to a custom one such as "#8e8e8e":
private void list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (list.SelectedItem != null)
{
ListBoxItem a = sender as ListBoxItem;
//a.Background=
PhoneApplicationService.Current.State["test"] = list.SelectedItem;
NavigationService.Navigate(new Uri("/Detail", UriKind.Relative));
}
list.SelectedIndex = -1;
}
So i need to chnage the selected item background color to #8E8E8E from C# for simplicity because changing the states seems a bit complicated especially that all i need to do is change background color of the selected item.
Thanks in advance,

Although not recommend like Matt already pointed out you should be able to achieve this by using ControlTemplates and Visual States. Check out this article on windowsphonegeek to see how: Part 1 Part 2
Please let us know if you encounter any problems

You should look at the visual states for selected items if you wish to do this.
However, standard behaviour for Metro apps and recommended design best practices advise not to use colour to indicate selection in anythign other than the ListPicker.
Without seeing your app, how you're using the ListBox or the purpose of indicating selection it's hard to advise further though.

Related

Using an English only keyboard in a Xamarin.Forms Entry view

Pretty much what the title says.
I have a page with an Entry view in it in my Xamarin.Forms app.
Clicking it brings up the software keyboard which, under all text based keyboard settings(such as url, email, text, etc.), has the option to change the input language.
My problem is that my backend accepts English only, and that's the way I want it as well, but I just can't find a way to disable the language choice on the keyboard.
Does anyone know?
I'm using Xamarin.Forms, and the above description relates to usage on an Android device, I'm yet to test on iOS.
I'm hoping for a cross platform solution that I can use in the PCL, but a solution using custom renderers is acceptable too if no XForms solution exists.
Thanks!
You can do something else to enable only english characters - you can hook to the text changed event of the entry and check inside if the text is english or not.
You can do something like this:
private void MyEntry_TextChanged(object sender, TextChangedEventArgs e)
{
var newText = ((Entry)sender).Text;
// Check for english characters.
...
// If not english, put the old value
((Entry)sender).Text = e.OldTextValue;
}

wxWidgets event focus textcontrol

I have another wxWidgets question regarding events and focus.
I have already looked at the tutorials and this old question here but I am still running into problems C++ Event (Focus) Handling
Basically I have a dialog with two wxTextCtrl elements and a Button.
What I would like to achieve is, that when I click on button it needs to tell me which of the two elements previously had the focus.
In the constructor of my Dialog I created all the elements and then connected them to the eventhandler like this: Ttop->Connect(TOP,wxEVT_KILL_FOCUS,(wxObjectEventFunction)&UI_ADDENTRY::hasfocus);
Tbottom->Connect(BOTTOM,wxEVT_KILL_FOCUS,(wxObjectEventFunction)&UI_ADDENTRY::hasfocus);
then there is the eventhandler that safes the id into focus
void UI_ADDENTRY::hasfocus(wxFocusEvent& event){
focus= event.GetId();
event.Skip();}
however when i try to access focus in the Button function it always tells me: 0 instead of TOP or BOTTOM / the ids that I gave the textcontrols
void UI_ADDENTRY::OnRecord(wxCommandEvent &event){
wxString tmp;
tmp << this->focus;
wxMessageBox(tmp);}
What am I doing wrong? is there another way of finding out which of the two textbox has been in focus last?
Thank you
The most fool proof way is to catch EVT_SET_FOCUS in your text controls and remember the last one that received it. This is not more difficult than what you are doing but should work without problems.
FWIW EVT_KILL_FOCUS can't, unfortunately, be consistently implemented on all platforms, in particular GTK+ doesn't give any information about the window focus is being lost to.
In think u mean event.GetWindow().GetId(). Though I'm not sure how ur casting from int to string.

ImageMap behavior for tiles

Is it possible to determine the area on which a user clicked on a tile? Just like an image map in HTML. I would like to specify two buttons at an image tile and carry out different actions for each of them.
No. It is not possible to do this.
With respect of lauching your app, the tile works just like a shortcut on your PC desktop.
If you really need the behaviour you describe you'll have to create 2 applications - 1 for each launch action.
You can use something like this for every UI element.
private void ListBox_MouseEnter(object sender, MouseEventArgs e)
{
string pos= e.GetPosition(CanvasForLoop).X.ToString();
}

prevent blend from adding a startupURI to application?

Is there some trick that is known to tell blend to stop trying to set a startupURI in my app.xaml? I googled but didn't see anything so I figured I would ask here.
I use a startup routine and instantiate mainwindow myself. Every once and a while blend likes to toss in the startupURI="MainWindow.xaml" when I let it compile. Occasionally I see some message along of the lines of "There is no startup scene associated with this project. Would you like blend to blah blah fix it?" or something along those lines. I click cancel/no yet it still tosses a gremlin in my code. Internal to blend there is some mechanism for checking for this property or it wouldn't complain via dialog box to me. So how do I just tell it "no thanks blend, i'm good without that?", lol.
Its quite annoying. I open blend to do something simple like using a color picker and use it to compile because VS2010 isn't open. My result is two mainwindows. But it does not do it every time so it's not a repeatable behavior. The compiler just acts out randomly.
edit: I'm using blend 4 but I saw this happen when i was using blend 3 also.
This is a horrible, terrible hack, but hey, it works. By default, StartupUri is null, but you can't set it to null using the property, so you can go around the property if you like to live on the edge.
// Dangit blend! Stop inserting a stupid StartupUri
private void FixStartupUri()
{
var type = typeof(Application);
var startupUri = type.GetField("_startupUri", BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.Instance);
startupUri.SetValue(this, null);
}
Add this to your Application class and call it like so:
protected override void OnStartup(StartupEventArgs e)
{
FixStartupUri();
base.OnStartup(e);
// Do the rest of your startup stuff.
}

Changing ListBox selection is not moving changes from BindingSource to DataSet

The answer to this question may turn out to be, "Don't use typed DataSets without using the Binding Navigator."
I am curious, however, about the behavior I'm seeing.
So, I created a form where every control was dragged from the data sources explorer.
I deleted the Binding Navigator because it is ugly and inappropriate for this particular form.
I added a ListBox and set the DataSource to the BindingSource.
Notice that the ListBox is not bound, it is just filling itself from the BindingSource.
By some magic that I wasn't counting on, moving around in the ListBox is navigating the BindingSource and all other controls are updating accordingly.
I can make changes to the bound controls and explicitly call EndEdit on the BindingSource and then update the DataSource through the Table Adapter. Works great.
When I make changes in the bound controls and click a new option in the ListBox, I want to be able to check for changes and prompt to save or reset if there are any.
Here is the strange part that I haven't been able to figure out.
No matter what event I attach to, DataSet.HasChanges doesn't return true until the second ListBox change.
I've searched and tried dozens of suggestions, most of them ridiculous, but a few that seemed promising.
No luck.
Edit: It isn't the second click that is significant, it is when you click back on the original (edited) item.
Since asking the question, I've learned a bit more about BindingSources, DataSets and TableAdapters.
Here is what works:
private void MyListBox_Click(object sender, EventArgs e)
{
this.myBindingSource.EndEdit();
if (myDataSet.HasChanges())
{
if (MessageBox.Show("Save changes?", "Before moving on", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
myTableAdapter.Update(myDataSet.myDataTable);
}
else
{
myDataSet.RejectChanges();
}
}
}

Resources