【发布时间】:2012-07-16 02:27:00
【问题描述】:
您好,我想知道如何将 MainWindow.xaml 分成不同的 xaml 文件?我想外包我的样式,并在需要时将它们包括在内。我搜索了一些解决方案,发现了一些 stackoverflow 帖子,但没有一个对我有帮助。
我想实现这样的事情(伪代码)
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
Title="MyApp" Height="350" Width="525">
<Window.Resources>
//Import external xaml file with textbox style here
//instead of:
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
//add code here
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBox Width="60"/>
<Button Content="Button" Height="23" Name="button1" Width="75" />
</StackPanel>
【问题讨论】: