用于手写识别汉字等 public partial class InkTablet : INotifyPropertyChanged
 public partial class InkTablet : INotifyPropertyChanged
    {
        public InkTablet()
        {
            InitializeComponent();
            theInkCanvas.MouseUp = OnInkCanvasMouseUp;
        }
private Visibility _isTabletVisible;
        public Visibility IsTabletVisible
        {
            get
            {
                return this._isTabletVisible;
            }
            set
            {
                if (value != this._isTabletVisible)
                {
                    this._isTabletVisible = value;
                    this.NotifyPropertyChanged("IsTabletVisible");
                }
            }
        }
private ICommand _newCommand;
        public ICommand NewCommand
        {
            get
            {
                return this._newCommand ?? (this._newCommand = new DelegateCommand(this.OnNewClick));
            }
        }
        private void OnNewClick()
        {
            this.theInkCanvas.Strokes.Clear();
            this.StrokeWordList = new List<StrokeWord>();
        }
private IList<StrokeWord> _strokeWordList;
        public IList<StrokeWord> StrokeWordList
        {
            get
            {
                return this._strokeWordList;
            }
            set
            {
                this._strokeWordList = value;
                this.NotifyPropertyChanged("StrokeWordList");
            }
        }
        private void OnInkCanvasMouseUp(object sender, MouseButtonEventArgs e)
        {
            InkAnalyzer theInkAnalyzer = new InkAnalyzer();
            AnalysisHintNode hint = theInkAnalyzer.CreateAnalysisHint();
            hint.Guide.Columns = 1;
            hint.Guide.Rows = 1;
            hint.WordMode = true;
            hint.TopInkBreaksOnly = true;
            hint.Location.MakeInfinite();
            theInkAnalyzer.RemoveStrokes(theInkCanvas.Strokes);
            theInkAnalyzer.AddStrokes(theInkCanvas.Strokes);
            theInkAnalyzer.SetStrokesLanguageId(theInkCanvas.Strokes, 0x0804);
            theInkAnalyzer.SetStrokesType(theInkCanvas.Strokes, StrokeType.Writing);
            AnalysisStatus status = theInkAnalyzer.Analyze();
            if (status.Successful)
            {
                List<StrokeWord> slist = new List<StrokeWord>();
                //textBox1.Text = theInkAnalyzer.GetRecognizedString();
                for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i )
                {
                    string resultStr = theInkAnalyzer.GetAlternates()[i].RecognizedString;
                    if (resultStr.Length == 1)
                    {
                        StrokeWord sw = new StrokeWord();
                        sw.StrokeName = resultStr;
                        slist.Add(sw);
                    }
                }
                this.StrokeWordList = slist;
            }
            else
            {
                MessageBox.Show("识别失败");
            }
        }
private string _nameStr;
        public string NameStr
        {
            get
            {
                return this._nameStr;
            }
            set
            {
                if (value != this.NameStr)
                {
                    this._nameStr = value;
                    this.NotifyPropertyChanged("NameStr");
                }
            }
        }
private ICommand _itemCommand;
        public ICommand ItemCommand
        {
            get
            {
                return this._itemCommand ?? (this._itemCommand = new DelegateCommand<Button>(this.OnItemClick));
            }
        }
        private void OnItemClick(Button btn)
        {
            this.NameStr = btn.Tag.ToString();
            this.OnNewClick();
        }
private ICommand _sureCommand;
        public ICommand SureCommand
        {
            get
            {
                return this._sureCommand ?? (this._sureCommand = new DelegateCommand(this.OnSureClick));
            }
        }
        private void OnSureClick()
        {
            this.IsTabletVisible = Visibility.Hidden;
        }
public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string property)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }        

 
  
					
				
评论