トルネード

メモ書き

UWP VC++ TreeView

Visual Studio 2017 VC++ UWPでのTreeView

xaml

<Grid>
    <TreeView Name="TreeView1" Loaded="TreeView1_Loaded" ItemInvoked="TreeView1_ItemInvoked"/>
</Grid>

VC++コード

void test::TreeView1_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
   #define IntToStr( ii ) static_cast<std::wstringstream &>( ( std::wstringstream() << std::dec << ii ) ).str()
    TreeViewNode^ temp;
    TreeViewNode^ next;
    for (int i1 = 0; i1 < 10; ++i1)
    {
        std::wstring item_content = L"アイテム = " + IntToStr(i1);

        temp = ref new TreeViewNode();
        temp->IsExpanded = true;
        temp->Content        = ref new Platform::String(item_content.c_str());
        switch (i1)
        {
        case 0:
            TreeView1->RootNodes->Append(temp);
            break;
        default:
            next->Children->Append(temp);
            break;
        }
        next = temp;
    }
}

TreeView ItemInvokedイベント

void test::TreeView1_ItemInvoked(Windows::UI::Xaml::Controls::TreeView^ sender, Windows::UI::Xaml::Controls::TreeViewItemInvokedEventArgs^ args)
{
    TextBox1->Text = static_cast<TreeViewNode^>(args->InvokedItem)->Content->ToString();
}

f:id:mojeld:20180813160240g:plain

参考

mojelder.hatenablog.com