1 year ago

#311353

test-img

LegitLearner

How to get the DisplayName of the package in C++/WinRT?

i would like to get the DisplayName of the package in C++/WinRT.

As describe in this C# example:

<TextBlock x:Name="AppTitle"
                       Text="{x:Bind GetAppTitleFromSystem()}"
                       VerticalAlignment="Center"
                       Style="{StaticResource CaptionTextBlockStyle}" />
namespace AppUIBasics
{
    public sealed partial class NavigationRootPage : Page
    {
        public string GetAppTitleFromSystem()
        {
            return Windows.ApplicationModel.Package.Current.DisplayName;
        }
    }
}

i tried to :

// .xaml.h file
struct MainWindow : MainWindowT<MainWindow>
{
        MainWindow();
        winrt::hstring GetAppTitleFromSystem();
}
...
// .xaml.cpp file
...
MainWindow::MainWindow()
{
        InitializeComponent();        
}
hstring MainWindow::GetAppTitleFromSystem()
{
        Package package = Package::Current();
        return package.DisplayName();
}
...
// .idl
namespace Example
{
    [default_interface]
    runtimeclass MainWindow : Microsoft.UI.Xaml.Window
    {
        MainWindow();

        String GetAppTitleFromSystem{ get; };        
    }
}

i got error like:

2.Error XLS0525 Method 'GetAppTitleFromSystem' not found in type 'MainWindow. Example C:\Users\{..}\MainWindow.xaml 72

xaml

c++-winrt

winui-3

midl

0 Answers

Your Answer

Accepted video resources