111,101
社区成员




<Window x:Class="SQRC_ViewModel觖发修改ViewModel属性.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="{Binding Title}" Height="350" Width="525">
<Grid>
<Border Name="brInkMessage" Grid.Column="1" Grid.Row="2">
<StackPanel>
<TextBox x:Name="txt3" Text="{Binding IsLogin, UpdateSourceTrigger=PropertyChanged}" />
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsLogin}" Value="True">
<ei:ChangePropertyAction TargetObject="{Binding}" PropertyName="Title" Value="Changed" />
</ei:DataTrigger>
</i:Interaction.Triggers>
</StackPanel>
</Border>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SQRC_ViewModel觖发修改ViewModel属性
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowViewModel();
}
}
class MainWindowViewModel : NotificationObject
{
private string title;
/// <summary>
/// ??
/// </summary>
public string Title
{
get { return title; }
set
{
title = value;
this.RaisePropertyChanged("Title");
}
}
private bool isLogin;
/// <summary>
/// ??
/// </summary>
public bool IsLogin
{
get { return isLogin; }
set
{
isLogin = value;
this.RaisePropertyChanged("IsLogin");
}
}
}
class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
// 根据不同的登录状态显示不同的标题
private string title1="title login", title2 = "title not login";
public string Title
{
get { return IsLogin? title1 : title2 ; }
}