当我在uwp中使用x:bind时出错:无效的绑定路径err

时间:2019-05-28 14:44:45

标签: c# uwp uwp-xaml

我尝试使用x:bind函数显示String,它使用String.Concat()连接两个字符串。我按照此网站上的指示进行操作:https://docs.microsoft.com/en-us/windows/uwp/data-binding/function-bindings

由于这是堆栈溢出的第一个问题,如果我提出的方法有误,请指出。谢谢(≧∀≦)ゞ

我尝试在另一个命名空间中创建的函数中使用System.Contact(),并且看起来不错。

xmlns:sys="using:System"
xmlns:local="using:uwpppp.Scenes.ReciteF">

...

<TextBlock Text="{x:Bind sys:String.Concat('hello','123')}"/><!--not good-->

<TextBlock Text="{x:Bind local:Showdetail.GetString('hello','hello2')}"/><!--good-->
public static String GetString(string a, string b)
{
    return String.Concat(a, b);
}

无效的绑定路径'sys:String.Concat('hello','123')':函数参数'1'无效或不匹配

1 个答案:

答案 0 :(得分:2)

根据documentation,我认为问题出在这一点:

  

重载基于参数的数量而不是类型,它将尝试匹配具有多个参数的第一个重载

String.Concat有许多不同的重载,而x:Bind机制最有可能首先发现(object,object)重载,这会导致您看到的错误:

Invalid or missmatched parameter at position '1'.

如果使用自定义方法,则只有一个重载,因此可以清楚地使用(string, string)参数。