Windows::UI::ViewManagement::ApplicationView::Title doesn't work when only the case is different

-- 1 Reputation point
2020-03-10T11:47:03.393+00:00
  1. Create a blank uwp project (language independent, this example is c++/cx).
  2. Edit MainPage.xaml.cpp.

MainPage::MainPage()
{
InitializeComponent();
auto const btn1 = ref new Button();
btn1->Content = L"AAA";
btn1->Click += ref new RoutedEventHandler(
{
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title = L"AAA";
});
auto const btn2 = ref new Button();
btn2->Content = L"aaa";
btn2->Click += ref new RoutedEventHandler(
{
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title = L"aaa";
});
auto const btn3 = ref new Button();
btn3->Content = L"123";
btn3->Click += ref new RoutedEventHandler(
{
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title = L"123";
});
auto const panel = ref new StackPanel();
panel->Children->Append(btn1);
panel->Children->Append(btn2);
panel->Children->Append(btn3);
Content = panel;
}

Click on these buttons and will find that the window title is incorrect, is this a bug?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,206 Reputation points
    2020-04-17T06:26:11.9+00:00

    Hello,

    ​Welcome to our Microsoft Q&A platform!

    We’ve identified the cause and are considering a change for a future release of Windows 10. Currently, as a workaround, you can add a space to the end of the value, or if a space already exists at the end, Trim it. For example:

    Update:

    void ChangeTitleAppCX::MainPage::MySetTitle(Platform::String^ title)
    {
        auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
        view->Title = title;
    
        bool shouldTrimForMismatch = true;
    
        std::wstring str = view->Title->Data();
        std::wstring str1 = title->Data();
    
        str.erase(str.find_last_not_of(L" ") + 1);
        str1.erase(str1.find_last_not_of(L" ") + 1);
    
        while (!str._Equal(str1)) 
        {
    
            wchar_t myString[1024] = L" ";
            const wchar_t* lastCharacter = title->Begin() + (title->Length() - 1);
    
            if (!wcscmp(lastCharacter, myString) && shouldTrimForMismatch)
            {
    
                std::wstring wsstr(title->Data());
                wsstr.pop_back();
                title = ref new Platform::String(wsstr.c_str());
            }
            else
            {
                title = Platform::String::Concat(title, L" ");
            }
    
            view->Title = title;
            shouldTrimForMismatch = false;
    
            str = view->Title->Data();
            str1 = title->Data();
            str.erase(str.find_last_not_of(L" ") + 1);
            str1.erase(str1.find_last_not_of(L" ") + 1);
        }
    }