Caliburn Micro和RichEditBox

时间:2018-03-03 11:57:30

标签: c# binding uwp attached-properties richeditbox

我想在RichEditBox上进行双向绑定。对于此控件,我必须使用附加属性,因为Text没有RichEditBox或类似属性。

public static class RtfText
{
    public static string GetRichText(DependencyObject obj)
    {
        return (string)obj.GetValue(RichTextProperty);
    }

    public static void SetRichText(DependencyObject obj, string value)
    {
        obj.SetValue(RichTextProperty, value);
    }

    // Using a DependencyProperty as the backing store for RichText.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty RichTextProperty =
        DependencyProperty.RegisterAttached("RichText", typeof(string), typeof(RtfText), new PropertyMetadata(string.Empty, Callback));

    private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var reb = (RichEditBox)d;
        reb.Document.SetText(TextSetOptions.FormatRtf, (string)e.NewValue);
    }
}

进行绑定。

<RichEditBox local:RtfText.RichText="{Binding Inputs, Mode=TwoWay}"/>

在视图模型中。

private string _inputs = string.Join(Environment.NewLine, new[] { "0, 0", "0, 1", "1, 0", "1, 1" });
public string Inputs
{
    get { return _inputs; }
    set { _inputs = value; NotifyOfPropertyChange(() => Inputs); }
}

但它不起作用。初始值放在富编辑框中。但编辑它们对此属性没有影响。有什么问题?

我想坚持使用Caliburn micro和WinRT,请不要提出其他工具包。谢谢。

This answer提供了一些景点,但那是PasswordBox。任何想法?

ConventionManager.AddElementConvention<PasswordBox>(
    RtfText.RichTextProperty,
    "???", // what to put in here?
    "???");

0 个答案:

没有答案