【问题标题】:How to bind NSAttributedString to UITextView如何将 NSAttributedString 绑定到 UITextView
【发布时间】:2014-12-18 16:18:41
【问题描述】:

我们正在使用 MVVMCross,但在将 NSAttributedString 绑定到 UITextView 时遇到问题。这很奇怪,因为相同的代码在不使用 BindingSet 并且也使用 Bindig 作为 Text 属性而不是 AttributedText 的情况下工作

如前所述,这行代码没有绑定,TextView 只是显示默认文本:

set.Bind (TxtActivityText).For(txt => txt.AttributedText).To (vm => vm.Activity).WithConversion("ActivitySpanMessage");

... 并输出以下警告: “MvxBind:Warning: 6.06 无法为 Activity 绑定 AttributedText 创建目标绑定”

虽然这条线工作正常:

set.Bind (TxtActivityText).For(txt => txt.Text).To (vm => vm.Activity).WithConversion("ActivitySpanMessage"); // Works fine also binding to the default property

最后,不使用绑定也可以正常工作:

TxtActivityText.AttributedText = SpanMessageHelper.ConvertToAttributedString(ViewModel.Activity, null, null, null); // This function is the same I call in the ActivitySpanMessageConverter

有什么想法吗?这可能是一个错误吗?

【问题讨论】:

  • trace中是否有调试信息?您是否可以在问题中提供更多信息 - 例如一些使用的代码值?它“可能是一个错误”(TM),但其他人已经看到属性文本绑定工作正常 - 例如。 stackoverflow.com/questions/17934294/…github.com/MvvmCross/MvvmCross/issues/791
  • 是的,它说 MvxBind:Warning: 6.06 Failed to create target binding for binding AttributedText for Activity。这很奇怪,因为它是一个非常简单的 casa:使用 xCode6 完成的简单 XIB,其他一些控件工作正常。明天我试试模拟器有没有问题
  • 请编辑问题以包含相关的跟踪和信息 - 在问题中比在 cmets 中更容易阅读。谢谢。

标签: ios xamarin.ios xamarin mvvmcross


【解决方案1】:

这可能是因为 Xamarin 链接器不包括 UITextView.AttributedText,因为它仅在表达式中使用。有关更多信息,请参阅此帖子:MvvmCross Failed to create target binding for EditingDidBegin on iPhone

您可以通过转到 LinkerPleaseInclude.cs 并更改您的 UITextView 包含方法来解决此问题:

public void Include(UITextView textView)
{
    textView.Text = textView.Text + "";
    textView.Changed += (sender, args) => { textView.Text = ""; };

    // Add this line here
    textView.AttributedText = new NSAttributedString();
}

【讨论】:

    猜你喜欢
    • 2011-07-29
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    相关资源
    最近更新 更多