当我在 uwp 中使用 x:bind 时出错:无效的绑定路径错误
Getting wrong when i use x:bind in uwp: invalid binding path err
我尝试使用 x:bind 函数来显示使用 String.Concat() 连接两个字符串的字符串。我遵循此网站的说明:https://docs.microsoft.com/en-us/windows/uwp/data-binding/function-bindings
由于是第一次在Stack Overflow上提问,如果我的提问方式有误,请指出。谢谢(≧∀≦)ゞ
我尝试在我在另一个命名空间中创建的函数中使用 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'无效或不匹配
根据documentation,我认为问题出在这一点上:
Overloading is based on the number of arguments, not type, and it will try to match to the first overload with that many arguments
String.Concat
有许多不同的重载,x:Bind
机制最有可能首先找到 (object,object)
重载,这会导致您看到的错误:
Invalid or missmatched parameter at position '1'.
对于您的自定义方法,您只有一个重载,因此它可以清楚地使用 (string, string)
参数。
我尝试使用 x:bind 函数来显示使用 String.Concat() 连接两个字符串的字符串。我遵循此网站的说明:https://docs.microsoft.com/en-us/windows/uwp/data-binding/function-bindings
由于是第一次在Stack Overflow上提问,如果我的提问方式有误,请指出。谢谢(≧∀≦)ゞ
我尝试在我在另一个命名空间中创建的函数中使用 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'无效或不匹配
根据documentation,我认为问题出在这一点上:
Overloading is based on the number of arguments, not type, and it will try to match to the first overload with that many arguments
String.Concat
有许多不同的重载,x:Bind
机制最有可能首先找到 (object,object)
重载,这会导致您看到的错误:
Invalid or missmatched parameter at position '1'.
对于您的自定义方法,您只有一个重载,因此它可以清楚地使用 (string, string)
参数。