找到您的引导程序代码(在显示 XAML 之前执行的代码)并创建简单的开关,该开关将根据操作系统版本选择正确的 XAML 文件。
Uri uri = new Uri("/OS7.xaml", UriKind.Relative);
StreamResourceInfo info = Application.GetResourceStream(uri);
XamlReader reader = new System.Windows.Markup.XamlReader();
var dic = (ResourceDictionary)reader.LoadAsync(info.Stream);
//then locate ResourceDictionary throgh Application.Current.Resources
yourDictionary.MergedDictionaries.Add(dic);
您还可以创建绑定到静态 OS 版本属性并切换 Button 模板的简单触发器,但它相当有限,因为您只能交换模板。它可能会帮助你;
<Window.Resources>
<ControlTemplate x:Key="OS7" TargetType="Button">
<Border x:Name="Border" CornerRadius="2" BorderThickness="1" Background="blue" BorderBrush="blue">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
<!-- DEFALT -->
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border" CornerRadius="2" BorderThickness="1" Background="red" BorderBrush="blue">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- Just an example. Replace IsMouseOver with DataTrigger and STATIC binding against OS version-->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Template" Value="{StaticResource OS7}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>