在ViewModel中的属性更新后查看不更新

时间:2013-11-20 03:44:16

标签: xaml mvvm windows-phone-8

所以我正在尝试实现一个ListBoxItem,它具有一个绑定到viewmodel中属性的TextBlock。但由于某种原因,即使在更新viewmodel属性之后,视图也不会更新。谁能给我一些指示?

在视图(xaml)

<phone:Pivot HorizontalAlignment="Left" Height="748" Margin="10,10,0,0" Grid.Row="1" Title="pivot" VerticalAlignment="Top" Width="460">
    <StackPanel x:Name="POIStackPanel" DataContext="{StaticResource POIViewModel}">
        <ListBoxItem x:Name="SelectedPOIItem">        
            <TextBlock Text="{Binding SelectedPickupPOI.label}" />
        </ListBoxItem>

        phone:PivotItem x:Name="GooglePivot" Header="Google">
                                <ListBox x:Name="GooglePOIList" 
                                    ItemsSource="{Binding GooglePOICollection}" 
                                    HorizontalAlignment="Left" 
                                    Height="441" 
                                    Width="436"
                                    SelectedItem="{Binding SelectedPickupPOI, Mode=TwoWay}"
                                    ItemTemplate="{StaticResource POIItemTemplate}" />
                            </phone:PivotItem>
    </StackPanel>
</phone:Pivot>

在viewmodel中

public ObservableCollection<PointOfInterest> GooglePOICollection { get; private set; }

public PointOfInterest SelectedPickupPOI
{
    get
    {
        return _selectedPickupPOI;
    }
    set
    {
        _selectedPickupPOI = value;
        NotifyPropertyChanged("SelectedPickupPOI");
    }
}

public PointOfInterestViewModel()
{
    this.GooglePOICollection = = new ObservableCollection<PointOfInterest>();
    this.SelectedPickupPOI = new PointOfInterest();
}

public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String propertyName)
{
    PropertyChangedEventHandler handler = PropertyChanged;
    if (null != handler)
    {
        handler(this, new PropertyChangedEventArgs(propertyName));
    }
}

我的PointOfInterest模型

public abstract class PointOfInterest : INotifyPropertyChanged
{
    public abstract string id { get; set; }
    public abstract string label { get; set; }
}

public class GooglePOI : PointOfInterest
{
    private string _label;

    public override string label
    {
        get { return _label; }
        set
        {
            _label = value;
            NotifyPropertyChanged("label");
        }
    }
}

更新 所以我发现如果我_selectedPickupPOI.label = value.label;,它会正确更新视图。我做错了什么?

0 个答案:

没有答案
相关问题