ListBox Menu in Windows Phone 7 - windows-phone-7

Howdy,
I want to make a dynamically filled Menu in Windows Phone 7. I thought that a listbox would be the perfect fit for that. However, I cannot get the "selectedValue" once the user interacts with the listbox - hence I cannot give any information to the navigationhandler.
How can I create a ListBox whose Listbox Items are created dynamically and navigate the User on click to the same page but with different parameters e.g.
\informations.xam?id=2

Not that long ago I wrote an WP7 application and I used something like this:
private void CategoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CategoryList.SelectedIndex == -1) return;
string id = (CategoryList.SelectedItem as DepartmentViewModel).ID;
NavigationService.Navigate(new Uri("/Views/CatalogueBrowser/CategoriesPage.xaml?deptId=" + id, UriKind.Relative));
CategoryList.SelectedIndex = -1;
}
Basically, I set my listbox's itemssource to an observable collection of particular view models, then you just access the selected view model object using the SelectedItem property of the listbox.

Create a new "Windows Phone Databound Application" and the boilerplate code generated as part of the project will show you how to do this.

Related

Windows Form Listview is not visually showing selected items

We have a tool that is being integrated into our application. We have some strict borders around us too in that we cannot modify the application except for our extensions. I have searched here, I've searched the internet, but cannot find any postings about this problem.
I have a Windows Form that contains a ListView and our user requires we create a checkbox to Select/Deselect all. I have the event handler for when the check box state changes and call the routine to set everything to Selected.
private void SelectAllEventHandler(object sender, EventArgs e)
{
ChangeState(RadCapListView, SelectAllRadcap.Checked);
}
private void ChangeState(SWF.ListView control, bool state)
{
if (control.CheckBoxes)
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Checked = state);
}
else
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Selected = state);
}
control.Refresh();
}
Going into debug mode all items are marked as selected.
Also at the control level SelectedItems is properly updated.
The issue is that visually the control just will not highlight the selected items like we have our WPF forms doing. As you can see in the code I also tried to refresh the control hoping that would show items selected, but no joy.
Has anyone solved this problem in getting selected items to display properly?
Thank!
Instead of using control.Refresh(), try control.Focus().

How to show the appointment page from a form region in outlook

I have a very simple outlook form region. It is configured as a separate item, and, it is set to appear whenever a we try to compose a new appointment item. (Meeting request).
Once I click the button above, it should populate the sender and go back to the main appointment page. The code to do that is:
private void button1_Click(object sender, EventArgs e)
{
item.RequiredAttendees = "John.Doe#contoso.com";
var exp = item.Application.ActiveInspector();
if (exp == null) Debug.Print("NULL");
else exp.ShowFormPage("Appointment");
}
But this doesn't do anything. What is the correct way of doing this?
Use the SetCurrentFormPage method of the Inspector class to display the specified form page or form region in the inspector.
As a workaround you may try to call the Appointment button programmatically. Use the ExecuteMso method of the CommandBars class to execute the control identified by the idMso parameter. See Office 2013 Help Files: Office Fluent User Interface Control Identifiers for the actual idMso values.

WP7 : Populating a ListBox depending on the input from another ListBox

I'm trying to add ListItems to a ListBox (ListBox3) depending on the selectedItem of another ListBox (ListBox1). The problem is , The Items aren't added to the Listbox.
Here's the code :
private void createlist()
{
if (listBox1.SelectedValue.ToString().Equals("EPL"))
{
ListBoxItem manchesterunited = new ListBoxItem();
manchesterunited.Content = "Manchester United";
listBox3.Items.Add(manchesterunited);
}
}
private void listBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
createlist();
}
createlist() does the changes and is called in the SelctionChanged() event of ListBox1.
New to C# and WP7 programming , any help will be much appreciated.
Create the lists in your viewmodel and bind the listbox to a list<> in your viewmodel say SelectedList. When the user selects the item from ListBox1 just change the value of SelectedList with the appropriate List and Notify the property changed event. And it will be done.!
i think you program not run in mvvm structure.
make sure your logic is right. you can make a breakpoint at the line
ListBoxItem manchesterunited = new ListBoxItem();
Ensure run those code in if code block.
the way add a control in a listbox is correct.

How to convert text in textblock from upper to lower case using checkbox click?

How to convert textblock text from upper to lower in main page when checkbox is clicked in another sample page? I am using c# which is for Windows Phone Apps
It'd be like this in C#:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
label1.Text = label1.Text.ToLower();
else
label1.Text = label1.Text.ToUpper();
}
where checkBox1 is your checkbox and label1 is name of your text field.
If you want to access it from another page and there are a bunch of things you'd like to access like that, I'd recommend creating a static class with references to these items so you can access them from anywhere.

Windows Phone 7 Selection_Changed automatically

currently I'm developing an app for WP7 but came across a little problem with a Listbox event call Selection_Change. The problem is that when i return to the page that contains the listbox the selection_change event triggers without being changed at all or without any user input. The listbox code is similar to this:
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
}
On the page I navigate to, the only way out of the navigated page is by pressing back button or start button meaning that it will return to the page that contains the listbox. When I Navigate back the selection change triggers leading me sometimes to a exception. Has anyone been through this before?
Consider always checking if it's -1 (the default value).
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
if (index != -1)
{
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
lsbHistory.SelectedIndex = -1; // Set it to -1, to enable re-selection.
}
}
Also, you should consider wrapping the Navigate call in Dispatcher.BeginInvoke to have a better, more smooth, page transition.
The event will be fired when the list is populated.
The simplest solution for you will probably be to add a check that there is nothing selected before triggering your navigation:
if (lsbHistory.SelectedIndex > -1)
{
// do navigation
}
One thing to notice is that when you navigate back to the page which containt the ListBox, the ListBox still has the SelectedItem set to the value it had when the user navigated away. This means that lsbHistory.SelectedIndex will get the index of the item which was selected when the user navigated forward.
Maybe there's something in your code which presumes that the ListBox's SelectedItem is null when the user navigates to the page?

Resources