Пример #1
0
 public override void OnApplyTemplate()
 {
     this.RichTextBox = this.GetTemplateChild(nameof(RichTextBoxEx)) as RichTextBoxEx;
     this.TitleBox    = this.GetTemplateChild("TitleBox") as TextBox;
     //this.OpenCommand = new OpenCommand(this.RichTextBox, this.TitleBox);
     this.RichTextBox.TextChanged += RichTextBox_TextChanged;
     this.TitleBox.TextChanged    += TitleBox_TextChanged;
     this.Command = new OpenCommand(TitleBox, this.RichTextBox, textChanges, titleChanges);
 }
Пример #2
0
        //{
        //    return true;
        //}

        public OpenCommand(TextBox textBox, RichTextBoxEx richTextBox, IObservable <string> textChanges, IObservable <string> titleChanges)
        {
            var ddd = Changes.Where(_ => _.GetType() != typeof(DocumentObject))
                      .Select(_ => new { properties = _.GetType().GetProperties(), obj = _ }).CombineLatest(
                textChanges,
                titleChanges,
                async(a, b, c) => await Task.Run(
                    () =>
            {
                string text  = (string)a.properties.SingleOrDefault(v => v.Name == b)?.GetValue(a.obj);
                string title = (string)a.properties.SingleOrDefault(v => v.Name == c)?.GetValue(a.obj);
                return(Tuple.Create(text, title));
            }).ToObservable()).SelectMany(_ => _);
            //.ObserveOnDispatcher()
            //.Subscribe(
            //    async _ => await richTextBox.Dispatcher.InvokeAsync(async () =>
            //        {
            //            var xx = await _;
            //        richTextBox.SetTextRange(xx.text);/*.Load(new MemoryStream(Encoding.ASCII.GetBytes(xx.text)), DataFormats.Text);*/
            //        textBox.Text = xx.title;
            //    },DispatcherPriority.Background));

            var eee = Changes.Where(_ => _.GetType() == typeof(DocumentObject))
                      .Select(_ =>
            {
                DocumentObject documentObject = _ as DocumentObject;
                return(Tuple.Create((string)documentObject.Text, documentObject.Title));
            });

            ddd.Merge <Tuple <string, string> >(eee)

            .ObserveOnDispatcher()
            .Subscribe(
                async _ =>
                await richTextBox.Dispatcher.InvokeAsync(async() =>
            {
                richTextBox.SetTextRange((string)_.Item1);        /*GetTextRange().Load(new MemoryStream(Encoding.ASCII.GetBytes((string)xx.Text)), DataFormats.Text);*/
                textBox.Text = _.Item2;
            }, DispatcherPriority.Background));

            //var text = ((parameter as FileObjectChangedEventArgs)?.Obj as TextObject)?.Text;
            //if (text != null)
            //{
            //    this.Editor.GetTextRange().Load(new MemoryStream(Encoding.ASCII.GetBytes(text)), DataFormats.Text);
            //}

            //var title = ((parameter as FileObjectChangedEventArgs)?.Obj as TextObject)?.Title;
            //if (title != null)
            //{
            //    (this.TitleEditor as TextBox).Text = title;
            //}
        }