question

10071398 avatar image
0 Votes"
10071398 asked FayWang-MSFT commented

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

  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([](Object^, RoutedEventArgs^)
{
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title = L"AAA";
});
auto const btn2 = ref new Button();
btn2->Content = L"aaa";
btn2->Click += ref new RoutedEventHandler([](Object^, RoutedEventArgs^)
{
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title = L"aaa";
});
auto const btn3 = ref new Button();
btn3->Content = L"123";
btn3->Click += ref new RoutedEventHandler([](Object^, RoutedEventArgs^)
{
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?





windows-uwp
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I can reproduce this issue and I'll report this strange behavior to the team to confirm it.

0 Votes 0 ·

Is anybody there???


0 Votes 0 ·

Hi, I'm still waiting for the team's confirm. If there is any response, I will update here.

0 Votes 0 ·

Hi, in addition, can you tell us what build version you have experienced?

0 Votes 0 ·

VS 2019 16.5.4 (c++ v142);
SDK 10.0.18362.0;
Windows 10 Pro 1903 18362.778.
For max compatibility I didn't use the latest version, there are still many users who haven't updated to 19H2.

0 Votes 0 ·

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered FayWang-MSFT commented

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);
     }
 }






· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This doesn't solve the problem, for example.

     ......
     btn1->Content = L"AAA";
     btn1->Click += ref new RoutedEventHandler([](Object^, RoutedEventArgs^) { SetTitle(L"AAA"); });        
     btn2->Content = L"aaa";
     btn2->Click += ref new RoutedEventHandler([](Object^, RoutedEventArgs^) { SetTitle(L"aaa"); });
     btn3->Content = L"AaA";
     btn3->Click += ref new RoutedEventHandler([](Object^, RoutedEventArgs^) { SetTitle(L"AaA"); });
     ......

7522-pic.png

This solves AAA and aaa, but what about AaA, add two space characters? aAa 3; Aaa 4, aAA 5, aaA 6, AAa 7? If it is abcdefghijklmn, how many spaces should I add? What if there are more characters, 2^n-1? And how to write code to implement this? And I don't understand why windows cached the title.

0 Votes 0 ·
pic.png (11.7 KiB)

I have updated the code snippet. If you need to set the Title as "AaA", you might need to loop to do the workaround, and continue adding spaces until the value dev set matches the value displayed. But using something like this, you could end up with very long gap in the title bar. How many times do you plan to do this? Or converting all titles to a consistent casing pattern such as all uppercase, all lowercase.

0 Votes 0 ·

The window title is the filename of the user selected file, like Microsoft Photos App, dozens of characters are common, the user may change the case, or the same filenames (only different case) in different folders. So the problem cannot be solved by adding a lot of spaces. This issue can only be fixed by Microsoft.

Let me explain again why it is impossible to solve this problem by adding spaces. Please take a look at the taskbar at the bottom of the screen, even if the window title is acceptable, what about the taskbar? After adding a few spaces, the taskbar will become very confusing.

If the solution is more confusing than the problem itself, I think this is not the right way.

0 Votes 0 ·
Show more comments