我显示成员全名列表,当我选择成员时,它将转到详细信息页面。我直接在文本框中编辑信息,然后单击应用程序栏中的保存,但信息在我编辑时没有更改......它仍然是旧值
请帮帮我!
我有这样的成员列表名称
<ListBox x:Name="Listmember" Height="500" SelectionChanged="Listmember_SelectionChanged" ItemsSource="{Binding Data}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="466" Margin="0, 0, 0, 12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0"></Grid>
<StackPanel Grid.Column="1" >
<TextBlock FontSize="40" Text="{Binding FullName}" Foreground="#FFEA0909" FontWeight="Normal" FontStyle="Normal" Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap"/>
</StackPanel>
<Grid Grid.Column="2">
<Button x:Name="Deletebutton" Height="60" Width="60" Click="deleteButton_Click" BorderBrush="{StaticResource TransparentBrush}">
<Image Source="/Assets/delete.dark.png" Visibility="{StaticResource PhoneDarkThemeVisibility}" Margin="-24"/>
</Button>
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和 SelectionChanged 是:
private void Listmember_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If no customer is selected, just return
if (Listmember.SelectedItem == null) return;
// Get the parent application that contains the customer being edited
App thisApp = Application.Current as App;
// Set this to the selected customer
thisApp.SelectedMember = Listmember.SelectedItem as Member;
// Navigate to the detail page
NavigationService.Navigate(new Uri("/View/MemberDetail.xaml", UriKind.RelativeOrAbsolute));
}
在导航到的 MemberDetails.xaml 中:
<Grid Name="ListDetails" Grid.Row="0">
<TextBlock Grid.Row="0" Name="fn" Text="FullName" FontSize="30" VerticalAlignment="Bottom"/>
<TextBox Grid.Row="1" Name="fullnameTextBox" Text="{Binding FullName, Mode=TwoWay}" TextWrapping="Wrap"/>
<TextBlock Grid.Row="2" Name="ad" Text="Address" FontSize="30" VerticalAlignment="Bottom"/>
<TextBox Grid.Row="3" Name="addressTextBox" Text="{Binding Address, Mode=TwoWay}" TextWrapping="Wrap" />
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton
IconUri="/Images/save.png"
Text="Save"
x:Name="SaveButton"
Click="Save_Click"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
和背后的代码
public MemberDetail()
{
InitializeComponent();
this.DataContext = App.MainViewModel;
}
ViewDetails view = new ViewDetails();
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Get the parent application that contains the active custom
App thisApp = Application.Current as App;
// Load the active customer into the viewmodel
view.LoadDetails(thisApp.SelectedMember);
// Set the data context to the viewmodel
ListDetails.DataContext = view;
}
private void Save_Click(object sender, EventArgs e)
{
App thisApp = Application.Current as App;
view.UpdateDetails(thisApp.SelectedMember);
// Go back to the previous page
NavigationService.GoBack();
}
和 ViewModel 中的 ViewDetails 类:
public class ViewDetails : INotifyPropertyChanged
{
private string _fullname;
public string FullName
{
get
{
return _fullname;
}
set
{
_fullname = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Fullname"));
}
}
}
private string _address;
public string Address
{
get
{
return _address;
}
set
{
_address = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Address"));
}
}
}
public void UpdateDetails(Member abc)
{
abc.FullName = FullName;
abc.Address = Address;
}
public void LoadDetails(Member abc)
{
FullName = abc.FullName;
Address = abc.Address;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
// Used to notify the app that a property has changed.
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}