viewmodel.cs
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
namespace mvvmtest.ViewModel
{
public class MainViewModel : ViewModelBase
{
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
Temp = 80;
doCmd = new RelayCommand(dowmtemp);
}
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
public int temp;
public int Temp
{
get { return temp; }
set { temp = value; RaisePropertyChanged(); }
}
private RelayCommand doCmd;
public RelayCommand DoCmd
{
get { return doCmd; }
set { doCmd = value; }
}
private void dowmtemp()
{
System.Windows.MessageBox.Show(temp.ToString());
}
//private int myvar;
//public int MyProperty
//{
// get { return myvar; }
// set { myvar = value; }
//}
}
}
xmal
<Window x:Class="mvvmtest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:mvvmtest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel>
<Button Content="Dome" Command="{Binding DoCmd}" FontSize="20" Margin="5" />
<!--<Button Content="Dome" FontSize="20" Margin="5" />-->
<Slider Minimum="0" Maximum="100" Value="{Binding Temp}" Margin="5" />
<TextBox x:Name="d" Text="{Binding Temp}" />
</StackPanel>
</Grid>
</Window>
xmal.cs
namespace mvvmtest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new ViewModel.MainViewModel();
}
}
}
data.cs
namespace mvvmtest.Model
{
public class data
{
public int Temp { get; set; }
public int Current { get; set; }//dianliu
public int dianya { get; set; }
}
}