为了简化向UI::XAML::TextBlock
添加文字,我写了一个函数:
public ref class MainPage sealed
{
public:
MainPage();
private:
void add_to_console(TextBlock^ text_block, String^ str)
{
text_block->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler(
[text_block, str]()
{
text_block->Text += str;
}));
}
};
但是,它会产生很多错误:
c2061 - syntax error - identifier TextBlock,
c2065 - undeclared identifier text_block.
我怎么能写这个函数才能使用任何TextBlock?
答案 0 :(得分:-1)
似乎在参数列表中我需要放置一个Platform :: Object ^ obj,然后
Windows::UI::Xaml::Controls::TextBlock^ text_block = reinterpret_cast<Windows::UI::Xaml::Controls::TextBlock^>(obj);
并按照我的意愿使用它