大佬教程收集整理的这篇文章主要介绍了silverlight mvvm sample,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
delegateCommand.cs:
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SelfPro.Practice.SilverlightTest1.Common { public class DelegateCommand : ICommand { private readonly Func<bool> _canExecute; private readonly Action _execute; public event EventHandler CanExecuteChanged; public DelegateCommand(Action executE) : this(execute,null) { } public DelegateCommand(Action execute,Func<bool> canExecutE) { _execute = execute; _canExecute = canExecute; } public bool CanExecute(object o) { if (_canExecute == null) { return true; } return _canExecute(); } public void Execute(object o) { _execute(); } public void RaiseCanExecuteChanged() { if (CanExecuteChanged != null) { CanExecuteChanged(this,EventArgs.Empty); } } } }
NotificationObject.cs:
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.ComponentModel; namespace SelfPro.Practice.SilverlightTest1.Common { public abstract class NotificationObject : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged(String propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { handler(this,new PropertyChangedEventArgs(propertyName)); } } protected void RaisePropertyChanged(params String[] propertyNames) { if (propertyNames == null) throw new ArgumentNullException("propertyNames"); foreach (var name in propertyNames) { this.RaisePropertyChanged(Name); } } } }
binding Helper.cs:
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SelfPro.Practice.SilverlightTest1.Common { public class BindingHelper { public static bool Getupdate@R_696_9016@eOnChange (DependencyObject obj) { return (bool)obj.GetValue(update@R_696_9016@eOnChangeProperty); } public static void Setupdate@R_696_9016@eOnChange (DependencyObject obj,bool value) { obj.SETVALue(update@R_696_9016@eOnChangeProperty,value); } // Using a DependencyProperty as the backing store for … public static readonly DependencyProperty update@R_696_9016@eOnChangeProperty = DependencyProperty.RegisterAttached( "update@R_696_9016@eOnChange",typeof(bool),typeof(BindingHelper),new PropertyMetadata(false,OnPropertyChanged)); public static void OnPropertyChanged (DependencyObject obj,DependencyPropertyChangedEventArgs E) { var txt = obj as TextBox; if (txt == null) return; if ((bool)e.Newvalue) { txt.TextChanged += OntextChanged; } else { txt.TextChanged -= OntextChanged; } } public static void OntextChanged(object sender,TextChangedEventArgs E) { var txt = sender as TextBox; if (txt == null) return; var be = txt.GetBindingExpression(TextBox.TextProperty); if (be != null) { be.update@R_696_9016@e(); } } } }
@H_755_18@mainwindowviewmodel.cs:
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using SelfPro.Practice.SilverlightTest1.Common; namespace SelfPro.Practice.SilverlightTest1.viewmodel { public class MainPageviewmodel:NotificationObject { private String inputStr; public String InputStr { get { return inputStr; } set { inputStr = value; RaisePropertyChanged("InputStr"); } } public DelegateCommand CmdRun { get; private set; } public MainPageviewmodel() { CmdRun = new DelegateCommand(new Action(Run),new Func<bool>(CanRun)); this.PropertyChanged += (s,E) => { CmdRun.RaiseCanExecuteChanged(); }; } private void Run() { InputStr = "aaa"; } private bool CanRun() { if (String.IsNullOrEmpty(inputStr)) return false; return inputStr.Equals("aaaaa"); } } }
@H_755_18@mainwindow.xaml:
<UserControl x:Class="SelfPro.Practice.SilverlightTest1.MainPage" xmlns="http://scheR_807_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_807_11845@as.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:SelfPro.Practice.SilverlightTest1.viewmodel" xmlns:cm="clr-namespace:SelfPro.Practice.SilverlightTest1.Common" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" xmlns:d="http://scheR_807_11845@as.microsoft.com/expression/blend/2008" xmlns:mc="http://scheR_807_11845@as.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" xmlns:toolkit="http://scheR_807_11845@as.microsoft.com/winfx/2006/xaml/presentation/toolkit" > <UserControl.DataContext> <vm:MainPageviewmodel></vm:MainPageviewmodel> </UserControl.DataContext> <UserControl.resources> <Style TargetType="Button"> <Setter Property="BACkground" Value="SkyBlue" /> <Setter Property="Width" Value="80" /> <Setter Property="Height" Value="24" /> </Style> </UserControl.resources> <Border BorderThickness="2" Margin="10" CornerRadius="10" Height="200"> <Border.BACkground> <LinearGradientBrush> <GradientStop Color="Green" Offset="0" /> <GradientStop Color="Wheat" Offset="1" /> </LinearGradientBrush> </Border.BACkground> <Border.borderBrush> <LinearGradientBrush> <GradientStop Color="SkyBlue" Offset="1" /> <GradientStop Color="SkyBlue" Offset="0" /> </LinearGradientBrush> </Border.borderBrush> <StackPanel> <Button Width="100" Height="25" Content="click me" Command="{Binding CmdRun}" /> <TextBox Text="{Binding InputStr,Mode=TwoWay}" Width="200" cm:BindingHelper.update@R_696_9016@eOnChange="True" /> </StackPanel> </Border> </UserControl>
以上是大佬教程为你收集整理的silverlight mvvm sample全部内容,希望文章能够帮你解决silverlight mvvm sample所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。