0
            <phone:LongListSelector 
                Margin="0,0,-12,0" 
                ItemsSource="{Binding CustomSounds.Items}"
                LayoutMode="Grid"
                GridCellSize="150,150"
                ItemTemplate="{StaticResource CustomSoundTileDataTemplate}" 
                SelectionChanged="LongListSelector_SelectionChanged" 
                x:Name="CustomSoundLongListSelector"
                />

我有一个这样的 LongListSelector,现在我在 CustomSounds.Items 中更改了一些内容并想重新加载它。我怎么能在文件后面的代码中做到这一点,CustomSoundLongListSelector.ItemSource = ...

4

3 回答 3

1

您可能希望INotifyPropertyChanged在 ViewModel 中实现接口以通知视图重新加载数据。我认为这是 MVVM 中非常标准的模式。

本质上:

公共类视图模型:INotifyPropertyChanged {

//... your other VM stuff...

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

然后当您更改项目时,您会说:

NotifyPropertyChanged("项目");

于 2013-11-14T20:09:46.070 回答
1

您应该在代码隐藏中执行以下操作:

CustomSoundLongListSelector.ItemsSource = model.CustomSounds.Items;

请注意,这里的“模型”是在您的页面上设置的 DataContext,或者更具体地说是在 LongListSelector 上设置的。

于 2013-11-14T18:18:58.753 回答
0

如果您将 Observable 集合用于项目源您不必实现INotifyPropertyChanged它会自行工作

于 2013-11-18T13:17:07.773 回答