【问题标题】:WP7 dynamic ListBox with GPS value带 GPS 值的 WP7 动态 ListBox
【发布时间】:2012-03-01 14:53:08
【问题描述】:

我会尽力解释我的问题...抱歉谷歌的英文翻译。

我想动态显示gps listBox中的值

我有一个类,股票值gps:

public class LocationManager : INotifyPropertyChanged

另一个具有名称和值的:

public class GpsItem: INotifyPropertyChanged

第三类:

 public class GpsItems: ObservableCollection<GpsItem>

我的列表框有 ItemsSource 作为我的第三类

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>

执行中显示的值,但不是动态的。

我已经实现了 INotifyPropertyChanged 接口:

    // 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));
        }
    }

我不知道该怎么办...帮助 提前谢谢你

【问题讨论】:

    标签: c# silverlight windows-phone-7 gps windows-phone-7.1


    【解决方案1】:

    你的NameValue应该是这样实现INotifyPropertyChanged接口的:

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

    【讨论】:

    • 您真的会动态更新Name&amp;Value 属性还是在更新发生时发出问题?在setter 中设置断点Debugger
    • 显然,名称和值永远不会在 ObservableCollection 中更新
    【解决方案2】:

    您可以查看How to: Get Data from the Location Service for Windows PhoneLocation Service Sample 也非常有用。

    这对我了解如何使用 GPS 有很大帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      相关资源
      最近更新 更多