2
我有一個處理模板的難題。請幫幫我。將模板應用於wpf窗口時出現的神祕的運行時錯誤
的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>
======== ======== =====
問題#1
運行該程序時,IDE occure運行時錯誤:XmlParseException。 所以我在app.xaml中添加一行,它正常運行。該行是:StartupUri =「CMainWindow.xaml」。
這是什麼?模板和startupuri有什麼關係?請告訴我這件事。
問題#2
當我添加控制CMainWindow,它沒有apeear連我設置窗口中的模板。
如何在這種情況下正確添加控件?
謝謝。
謝謝你的答案。我做了獨立的窗口風格的資源字典爲全球風格,然後它正常工作。 – mjk6026