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



我尝试使用 x:bind 函数来显示字符串,该函数使用 String.Concat(( 连接两个字符串。我遵循本网站的说明:https://learn.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' 无效或不匹配

根据文档,我认为问题出在这一点上:

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

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

Invalid or missmatched parameter at position '1'.

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

相关内容

最新更新