WP7 – set ListBoxItem.IsSelected to true from c#

This question has received: 0 Votes.

I have a ListBox with multiple ListBoxItems. I want to set some of these to ‘selected’. I am trying the following but it does not work:

ListBoxItem1.IsSelected = true;

The result is that it compiles with no error, but the list item remains unselected.

Any ideas? many thanks! will.

Wed Sep 14 17:29:03 AST 2011
Answer #: 1
This answer has received: 3 Votes.

So I can’t attest to why that happens and if it is a WP7 thing as the docs clearly state:

To select a ListBoxItem in a ListBox, set this property to true.

However, you can always use the ListBox.SelectedItems property:

// to add
listBox.SelectedItems.Add( someItem );

// to remove
listBox.SelectedItems.Remove( someItem );

// to clear
listBox.SelectedItems.Clear();

If multi-select is not enabled you can simply use the SelectedItem and/or the SelectedIndex properties.

Wed Sep 14 18:02:27 AST 2011
This question and its answers are found at: WP7 – set ListBoxItem.IsSelected to true from c#

WebBrowser disable copy paste

This question has received: 1 Votes.

I have a several question about WebBrowser control into WP7.

  1. How to disable word selection by a click?
  2. How to disable vertical scrollable by a gesture?
Wed Sep 14 21:15:51 AST 2011
Answer #: 1
This answer has received: 4 Votes.

Add some extra styles to your html pages and render it on WebBrowser control

  1. body {-ms-user-select: none;} use this css code to disable word selection by tap in IE on Windows phone 7/8

  2. body {-ms-touch-action: none;} use this css code to disable vertical scroll

    in IE on windows phone 7/8

hope this work fine for you.

Sat Feb 01 13:36:21 AST 2014
Answer #: 2
This answer has received: 1 Votes.

first , u can get a border control which is the container of the ie9 mobile core using visual tree helper

then

Q1: u can cancel the “Tap” gesture occurred in border control before it was passed to ie core

Q2: u can cancel the “DragDelta” gesture for some direction or distance ,well ie. vertical scroll.

Sat Jan 07 18:03:23 AST 2012
Answer #: 3
This answer has received: 0 Votes.

The answer to Copy and Past = “I don’t believe you can stop it from occurring, unless its your webpage and you can set it up for a Read Only Document.”-If i am wrong please correct me.-

the answer to Vertical Scrollable By a Gesture = “You could build the Gesture to Return a Null instead of the event value, Pretty much tell it that if this occurs then Cancel it….Return Nothing!”

Wed Sep 14 22:09:32 AST 2011
Answer #: 4
This answer has received: 0 Votes.

You can achieve disabling selection using javascript:

function DisableSelect() { var handler = function (e) {e.returnValue = false;} document.body.attachevent('onselectstart',handler,false);}

and than calling from your code:

wb.InvokeScript("DisableSelect");

Don’t forget to detach the event.

Fri Oct 05 15:55:57 AST 2012
This question and its answers are found at: WebBrowser disable copy paste

How can I store the data of a windows phone when the user press Start button?

This question has received: 0 Votes.

Something is wrong with my program, while is using the application and when exit and resume, the application crashes..

I’m using a List variable but, when the application resume, it has nothing in it.

I was using this.

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        if (State.ContainsKey("c"))
        {
            App.Contenedor.Add((List<int>)State["c"]);
        }
    }

    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        State["c"] =(List<int>)App.Contenedor[0];
    }

It seems working, but I’m not sure.. what do you think people?

Tue Sep 20 04:42:26 AST 2011
Answer #: 1
This answer has received: 2 Votes.

You need to read up on Tombstoning, the process where application sleeps while not active.

Check out the Activated and Deactivated events.

Tue Sep 20 04:46:09 AST 2011
Answer #: 2
This answer has received: 1 Votes.

You are saving/restoring data in the wrong methods. You shoud be saving data in OnNavigatedFrom and restoring data in OnNavigatedTo.

Tue Sep 20 06:41:21 AST 2011
Answer #: 3
This answer has received: 0 Votes.

The Tombstoning is rarely invoked in Mango anymore – your application sort of exists in limbo while you are using other apps on the phone.

All the events that have to do with saving and restoring state are in App.xaml.cs – respond to them if necessary.

Tue Sep 20 05:09:37 AST 2011

Windows Phone 7 XML populate to List Box query

This question has received: 0 Votes.

I have a XML which has multiple records. I would like to populate those records to the listbox using the below code.

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                System.Diagnostics.Debug.WriteLine("Error: "+e);
            }
                XElement coupon = XElement.Parse(e.Result);

                MainListBox.ItemsSource = from query in coupon.Descendants("cs")
                                           select new ViewModels.LoadCoupon()
                                            {
                                                CouponName = (string)query.Element("c").Attribute("t"),
                                                //MerchantImage = dB.getBaseUri() + "images/merchant/" + (string)query.Element("ms").Element("m").Element("id")
                                                MerchantImage = dB.getBaseUri() + "images/merchant/" + (string)query.Element("c").Attribute("mId") + ".png"
                                            };

        }

Where MainListBox is my list box. Using the above code I am able to populate only one record. I know I am missing something. Can anyone please let me know what I need to do in order to display multiple records from the XML. I have copied a sample XML that I am using. Thank you.

<d>
      <ms>
        <m id="9921" n="The Book Company" />
        <m id="6333" n="Earth Rental" />
        <m id="6329" n="The Organic Baker" />
        <m id="6331" n="News Stand" />
        <m id="6327" n="The Jam Company" />
        <m id="6325" n="The Fruit Company" />
      </ms>
      <cs>
        <c id="14533" mId="9921" t="50% Off Any Book Purchase">
          <ls>
            <l id="40145" lng="-0.0724" lat="51.5024" d="4.97" dim="45.91" intX="" intY="" intL="" />
          </ls>
          <cats>
            <cat id="41" />
            <cat id="43" />
          </cats>
          <as />
        </c>
<c id="14533" mId="9921" t="50% Off Any Book Purchase">
              <ls>
                <l id="40145" lng="-0.0724" lat="51.5024" d="4.97" dim="45.91" intX="" intY="" intL="" />
              </ls>
              <cats>
                <cat id="41" />
                <cat id="43" />
              </cats>
              <as />
            </c>
<c id="14533" mId="9921" t="50% Off Any Book Purchase">
              <ls>
                <l id="40145" lng="-0.0724" lat="51.5024" d="4.97" dim="45.91" intX="" intY="" intL="" />
              </ls>
              <cats>
                <cat id="41" />
                <cat id="43" />
              </cats>
              <as />
            </c>
        </cs>
    </d>
Tue Sep 20 10:50:17 AST 2011
Answer #: 1
This answer has received: 3 Votes.

You’ve only got one cs element, so it’s only yielding one element. I think you want this:

// Note the use of Descendants("c") here
MainListBox.ItemsSource = from query in coupon.Descendants("c")
                          select new ViewModels.LoadCoupon()
                          {
                              CouponName = (string)query.Attribute("t"),
                              MerchantImage = dB.getBaseUri() + 
                                                "images/merchant/" + 
                                                (string)query.Attribute("mId") +
                                                ".png"
                          };

EDIT: To find a specific element, I’d use:

var match = coupon.Descendants("c")
                  .Where(c => (string) c.Attribute("mId") == mId)
                  .Single();
Tue Sep 20 10:59:56 AST 2011
This question and its answers are found at: Windows Phone 7 XML populate to List Box query

Way to make Windows Phone 7 Panorama Items Text gather up?

This question has received: 0 Votes.

How would I allow panorama items text to gather up like in the picture below? (By the way the image is not mine).

Notice how the Panorama Item titles are like “Contacts Chats” not spaced out like regular Microsoft panorama has it? How would I do that?

Thanks.

enter image description here

Sat Oct 01 03:11:36 AST 2011
Answer #: 1
This answer has received: 3 Votes.

I’m pretty sure that is a Pivot Control, which looks similar to a Panorama Control.

There’s a good video at Channel 9 on the two controls: Windows Phone Design Days – Pivot and Pano

Sat Oct 01 04:28:54 AST 2011
This question and its answers are found at: Way to make Windows Phone 7 Panorama Items Text gather up?

ListPicker always crashes when ExpansionMode is set to FullScreenOnly

This question has received: 0 Votes.

How should I make my list picker open in full screen mode? When I set ExpansionMode to FullScreenOnly it crashes. I tried creating blank project and doing the same but it also crashes.

<toolkit:ListPicker Height="100" HorizontalAlignment="Left" Margin="53,37,0,0" Name="listPicker1" VerticalAlignment="Top" Width="200" ExpansionMode="FullScreenOnly">
            <toolkit:ListPickerItem Content="item1"/>
            <toolkit:ListPickerItem Content="item1"/>
            <toolkit:ListPickerItem Content="item1"/>
            <toolkit:ListPickerItem Content="item1"/>
            <toolkit:ListPickerItem Content="item1"/>
            <toolkit:ListPickerItem Content="item1"/>
        </toolkit:ListPicker>

How should I work around this problem ?

Sat Oct 01 11:30:22 AST 2011
Answer #: 1
This answer has received: 1 Votes.

Adding “item1” many times might create problem? try changing content to item1, item2…etc

If not so, try using listPicker1.Items.Add();

Sat Oct 01 11:41:16 AST 2011
Answer #: 2
This answer has received: 2 Votes.

There is a[n apparently known] bug where full mode causes an error when the items are defined in XAML.

As the other answer says, define your items in code and this issue is not seen.

Mon Oct 03 12:30:29 AST 2011
Answer #: 3
This answer has received: 0 Votes.

The problem is some bug in ListPicker that prevents it to display more than 5 items if they are directly provided from the XAML. Better use data binding and generate items via C#.

Sat Sep 13 12:34:16 AST 2014

Windows Phone 7 Add PivotItem to Pivot with code in real time, how?

This question has received: 0 Votes.

How can I add Pivot Items in runtime, and add some content to it?

Sat Oct 01 12:50:18 AST 2011
Answer #: 1
This answer has received: 3 Votes.

You can create PivotItems at runtime just like you would create any UIelement. For example like this:

PivotItem pitem = new PivotItem(); //create pivotitem                
pitem.Content =  //set pivotitem content
MyPivot.Items.Add(pitem);//Add pivotitem to your pivot
Sat Oct 01 22:54:18 AST 2011
This question and its answers are found at: Windows Phone 7 Add PivotItem to Pivot with code in real time, how?