Windows 通用应用 (XAML):不能使用给定的参数列表调用文本块>文本

Windows Universal app (XAML): textBlock->Text cannot be called with the given argument list

本文关键字:文本 调用 列表 参数 gt 应用 XAML 不能 Windows      更新时间:2023-10-16

我试图将textBlock设置为等于某些计算的结果,但由于某种原因,我得到了以下错误:"无法使用给定的参数列表调用"total是int。

string Result;
ostringstream convert;
convert << total;
Result = convert.str();
textBlock->Text = Result;

错误消息表示您将错误类型的参数传递给textBlock的Text属性,该属性需要Platform::String,但您传递了std::字符串。MSDN页面Strings(C++/CX)包含有关字符串构造和转换的更多详细信息,在处理字符串时,还需要注意ANSIUNICODE

以下是修改后的代码。注意,我已经将字符串更改为wstring(宽字符串,16位Unicode),这样我就可以用它构造一个Platform:String

wostringstream convert;
convert << total;
wstring str = convert.str();
String^ Result = ref new String(str.c_str());
tb1->Text = Result;