global title bar

Eduardo Gomez 4,256 Reputation points
2023-06-25T19:47:03.99+00:00

I want to customiza my TitleView, but I want it to be global, so everytime I create a new Window, the title bar will be custom

I tried this

<Application
    x:Class="Demy.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                <!--  Other merged dictionaries here  -->
            </ResourceDictionary.MergedDictionaries>
            <!--  Other app resources here  -->

            <!--  Title bar customization -->
            <Style TargetType="TitleBar">
                <Setter Property="BackgroundColor"
                        Value="DarkBlue" />
                <Setter Property="ButtonBackgroundColor"
                        Value="Transparent" />
                <Setter Property="ButtonForegroundColor"
                        Value="White" />
                <!--  Add more title bar customizations as desired  -->
            </Style>
            
        </ResourceDictionary>
    </Application.Resources>
</Application>

in the Application level

Unknown target type 'TitleBar'	
 public partial class App : Application {

        private IHost _host;

        public App() {
            InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs args) {
            _host = Host.CreateDefaultBuilder()
                .ConfigureServices(ConfigureServices)
                .Build();

            // Start the host
            _host.Start();

            // Resolve and activate the main window using dependency injection
            var mainWindow = _host.Services.GetRequiredService<NavWindow>();
            mainWindow.Activate();
        }

        private void ConfigureServices(IServiceCollection services) {
            // Register your dependencies here
            services.AddSingleton<NavWindowViewModel>();
            services.AddSingleton(provider => new NavWindow(provider.GetRequiredService<NavWindowViewModel>()));

            // Add other services as needed
        }
    }
}

I want all m windows to have transparent title bar

User's image

Windows development | Windows App SDK
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,736 Reputation points Microsoft External Staff
    2023-06-29T08:34:53.0233333+00:00

    As far as WinUI-Gallery is concerned, it sets "AppTitleBar" which is defined at NavigationRootPage.xaml as Title Bar. You would call the API sequence for every window. Also see the WinUI3_CustomCaption sample.

    Besides that, the navigation window's ExtendsContentIntoTitleBar is true.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.