Search code examples
c++wpfxamlwin-universal-apptextblock

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


I'm trying to set the textBlock equal to the result of some calculations, but for some reason i'm getting the following error: "cannot be called with the given argument list" total is an int.

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

Solution

  • The error message means that you are passing a parameter of a wrong type to the textBlock's Text property, which expects a Platform::String, but you pass a std::string. The MSDN page Strings(C++/CX) contains more details on string construction and conversions - also you need to be aware of ANSI and UNICODE when dealing with strings.

    Below is the modified code. Noted that I have changed string to wstring (wide string, 16-bit Unicode) so that I can construct a Platform:String with it.

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