说明:
我有两个目标:
要求:
View.xaml:
<Window....>
<Window.DataContext>
<VM:MyViewModel/>
/Window.DataContext>
<Grid>...
<TextBlock Text="Password" Margin="10" VerticalAlignment="Center"/>
<TextBox Text="{Binding ElementName=Mygroups,Path=DataContext.Password,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Width="200" Height="30" Grid.Row="0" Grid.Column="1" VerticalContentAlignment="Center" HorizontalAlignment="Left" ></TextBox>
<TextBlock Text="ConfirmPassword" Margin="10" Grid.Row="1" VerticalAlignment="Center"/>
<TextBox Text="{Binding ElementName=MyItems,Path=DataContext.Confirmpassword,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Width="200" Height="30" Grid.Row="1" Grid.Column="1" VerticalContentAlignment="Center" HorizontalAlignment="Left"></TextBox>
<Button Grid.Row="2" HorizontalAlignment="Right" Content="Save" Height="26" IsDefault="True" Width="95" />
</Grid>
</Window>
ViewModel.cs:
namespace Myproject.ViewModel
{
public class MyViewModel : INotifyPropertyChanged
{
public string Pwd
{
get { return pwd; }
set
{
pwd = value;
OnPropertyChanged("Pwd");
}
}
private string cfmpwd;
public string Cfmpwd
{
get { return cfmpwd; }
set
{
cfmpwd = value;
OnPropertyChanged("Cfmpwd");
}
}
}
}
对于上述情况,我应该在 View.xaml,ViewModel.cs 中写什么?
请帮助我...