简体   繁体   中英

WP7 dynamic ListBox with GPS value

I'll try to explain my problem ... Sorry for the English translation to Google.

I'd like to dynamically display the values ​​in a gps listBox

I have a class that stock values ​​gps:

public class LocationManager : INotifyPropertyChanged

another with the Name and Value:

public class GpsItem: INotifyPropertyChanged

and a third class:

 public class GpsItems: ObservableCollection<GpsItem>

My listbox which has ItemsSource as my third class

ListBox.ItemsSource = new GpsItems();

xaml:

<ListBox x:Name="ListBox" Background="#BF000000" Tap="LsbAllCases_Tap">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="0,0,0,10" Width="Auto" Height="Auto" Orientation="Horizontal">
                    <TextBlock Text="{Binding Name, Mode="OneWay"}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                <TextBlock Text="{Binding Value, Mode="OneWay"}"  HorizontalAlignment="Right" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

The value displayed in the execution but are not dynamic.

I have implemented the INotifyPropertyChanged interface with:

    // Declare the PropertyChanged event
    public event PropertyChangedEventHandler PropertyChanged;

    // NotifyPropertyChanged will raise the PropertyChanged event passing the
    // source property that is being updated.
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

I do not know what to do ... HELP Thank you in advance

You can look at How to: Get Data from the Location Service for Windows Phone and the Location Service Sample is very useful too.

It has helped me a lot to understand how use the GPS

Your Name and Value should be like that to implement INotifyPropertyChanged interface:

    private string name;
    [DataMemberAttribute]
    public string Name
    {
        get { return name; }
        set
        {
            if (name != value)
            {
                name = value;
                NotifyPropertyChanged("Name");
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM