Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:52:04+00:00 2026-05-24T00:52:04+00:00

i have a hard problem dealing with template. please help me. App.xaml <Application x:Class=WpfApplication1.App

  • 0

i have a hard problem dealing with template. please help me.

App.xaml

<Application x:Class="WpfApplication1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

//Note i didn't set a StartupURI in Application tag please.

    <Application.Resources>

        <Style TargetType="Window" x:Key="myWindowStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Rectangle Fill="gray" RadiusX="30" RadiusY="30"/>
                            <ContentPresenter/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Application.Resources>
</Application>

App.xaml.cs

using System;
using System.Windows;

namespace WpfApplication1
{
    public partial class App : Application
    {

        CMainWindow winMain;

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            winMain = new CMainWindow();
            winMain.ShowDialog();

        }

    }
}

CMainWindow.xaml

<Window x:Class="WpfApplication2.CMainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Style="{StaticResource myWindowStyle}" Background="Red">
</Window>

=====================

question #1

when run this program, ide occure a runtime error : XmlParseException.
so i add a line in app.xaml, it runs properly. that line is : StartupUri=”CMainWindow.xaml”.

what is this? what relationship between template and startupuri? please tell me about this.

question #2

when i add control to CMainWindow, it didn’t apeear even i set a in window’s template.

how can i add control properly in this situation?

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:52:05+00:00Added an answer on May 24, 2026 at 12:52 am

    question #1
    A WPF application is always centered around a window. You’re override of OnStartup is unnecessary. By setting the StartupURI the application will automatically start by displaying the window.

    There is no actual relationship between template and startupuri. You just happen to be using App.xaml to store global styles.

    question #2

    The magic field to add is “TargetType” on the control template. You have to explicitly say its for the window type.

    <Application x:Class="SimpleWPF.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
            <Style TargetType="Window" x:Key="myWindowStyle">
                <Setter Property="Template">
                    <Setter.Value>
                        <!-- Explicitly setting TargetType to Window -->
                        <ControlTemplate TargetType="Window">
                            <Grid>
    
                                <Rectangle Fill="gray" RadiusX="30" RadiusY="30"/>  
                                <ContentPresenter/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Application.Resources>
    </Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, please bear with me. I have hard time telling others my problem and
I'm using SubSonic 2.2 and sqlite and have encountered a problem when dealing with
I have a big problem dealing with data I try to download in my
Hi this question or problem i have its very hard i have search and
I'm a python newbie with a problem too hard to tackle. I have a
i have NP hard problem. Let imagine I have found some polynomial algorithm that
I'm facing a hard problem: Imagine I have a map of an entire country,
I'm facing a hard problem, I'm developing an app to capture video from both
I'm looking for best practices to solve this hard problem: My app has a
I always seem to have a hard time starting a new Firefox extension. Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.