【发布时间】:2015-06-07 01:42:02
【问题描述】:
我在应用程序中嵌入了一个 WPF 用户控件,它继承了应用程序的样式。我在设计用户控件时考虑了默认的 WPF 样式,它没有定义自己的资源/样式。但是,由于继承了宿主应用程序的样式,它看起来并不正确。如果用户控件只使用默认的 WPF 样式,我会更喜欢。有没有一种简单的方法可以做到这一点?
UserControl 本身包含一个System.Windows.Controls.Frame,它引用了一个System.Windows.Control.Page:
<UserControl x:Class="OrderParcelAddInPrototype.WpfControls.Controls.OrderParcelControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="450">
<Frame Source="/OrderParcelAddInPrototype.WpfControls;component/Pages/MainPage.xaml" />
</UserControl>
UserControl 或 Page 都没有定义自己的样式。
<Page x:Class="OrderParcelAddInPrototype.WpfControls.Pages.StartPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="450" Title="Main Page">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel VerticalAlignment="Top" MaxWidth="350" CanVerticallyScroll="True"
ScrollViewer.CanContentScroll="True">
<!-- Removed for brevity -->
</StackPanel>
</ScrollViewer>
</Page>
【问题讨论】:
-
请发布您的代码/XAML ?
-
你试过
<UserControl Style="{StaticResource {x:Type UserControl}}" />吗? -
我刚刚试了一下。它似乎无法解决问题。
标签: wpf xaml wpf-controls wpf-style