私はテンプレートを扱うのが難しいです。私を助けてください。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の間の関係は?これについて教えてください。私はCMainWindowにコントロールを追加するとき
質問#2
は、それは私は、ウィンドウのテンプレートに設定してもapeearませんでした。
どうすればこの状況に適切にコントロールを追加できますか?
ありがとうございました。
ご回答いただきありがとうございます。私はグローバルスタイルのためのリソース辞書に別々のウィンドウスタイルを行い、それが正しく動作します。 – mjk6026