0

我想做两种方式绑定RichEditBoxText对于这个控件,我必须使用 Attached属性,因为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,请不要推荐其他工具包。谢谢你。


这个答案给出了一些观点,但那是为了PasswordBox. 有任何想法吗?

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

0 回答 0