WPF 样式的一个问题
无法将类型为“MS.Internal.NamedObject”的对象强制转换为类型“System.Windows.FrameworkTemplate”。
在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
问题应该是出现在
<Setter Property="Template" Value="{StaticResource WindowControlTemplate}"></Setter>
Template某一个属性值不对 麻烦帮忙看一下
在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
问题应该是出现在
<Setter Property="Template" Value="{StaticResource WindowControlTemplate}"></Setter>
Template某一个属性值不对 麻烦帮忙看一下
<Style x:Key="ChildWinStyle" TargetType="{x:Type Window}">
<Setter Property="OverridesDefaultStyle" Value="True"></Setter>
<Setter Property="ResizeMode" Value="CanResizeWithGrip"></Setter>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="FontFamily" Value="Arial"></Setter>
<Setter Property="Window.BorderBrush" Value="#FF4C95BA"></Setter>
<Setter Property="Window.BorderThickness" Value="0"></Setter>
<Setter Property="Template" Value="{StaticResource WindowControlTemplate}"></Setter>
<!--Set Label and GroupBox foreground color-->
<Style.Resources>
<Style TargetType="{x:Type Label}" >
<Setter Property="Foreground" Value="{DynamicResource FontForeground}"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
<Style x:Key="lbBaseStyle" TargetType="{x:Type Label}">
<Setter Property="Height" Value="22"></Setter>
</Style>
<Style x:Key="tabControlStyle">
<Style.Resources>
<Style TargetType="{x:Type Label}" >
<Setter Property="Foreground" Value="#000000"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
</Style.Resources>
</Style>
</Style.Resources>
</Style>
<ControlTemplate x:Key="WindowControlTemplate" TargetType="{x:Type Window}" >
<Border x:Name="WinControlTpl_Border" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" BorderBrush="#FF4C95BA" BorderThickness="1" Background="White" CornerRadius="4" Padding="1">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform CenterX="400" CenterY="300" />
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
<Grid Background="{StaticResource WindowBackground}">
<AdornerDecorator>
<ContentPresenter/>
</AdornerDecorator>
<ResizeGrip x:Name="WindowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
</Border>
<ControlTemplate.Resources>
<Storyboard x:Key="OnLoaded1">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WinControlTpl_Border" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WinControlTpl_Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.1500000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WinControlTpl_Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.1500000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<ControlTemplate.Triggers>
<Trigger Property="ResizeMode" Value="CanResizeWithGrip">
<Setter TargetName="WindowResizeGrip" Property="Visibility" Value="Visible"/>
</Trigger>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
...全文
相关推荐
测试WPF全局样式对于字体大小的影响
理解WPF的样式系统和模板化机制是解决此类问题的关键。这不仅帮助我们调试和修复样式问题,还使我们能够构建更加一致和可维护的用户界面。
WPF样式继承与覆盖的艺术
WPF样式继承与覆盖机制解析:通过基于默认样式创建自定义样式,开发者可以灵活管理控件外观。文章以按钮样式为例,演示了从全局样式继承、覆盖特定属性到应用自定义样式的完整流程,并指出常见问题如样式优先级、属性覆盖和正确引用等注意事项。这种机制既保证了UI一致性,又提供了设计灵活性,有效提升代码可维护性。
WPF MessageBox 样式
在Windows Presentation Foundation (WPF) 中,`MessageBox` 是一个常用的小型对话框,用于向用户显示信息、询问问题或报告错误。
winform调用全局wpf资源样式
首先,WPF的资源样式通常定义在一个或多个`.xaml`文件中,这些文件可以视为样式库,包含各种控件的外观定义。要将这些资源引入到WinForm项目中,我们需要进行以下步骤:1.
WPF简单的Bootstrap样式
例如,如果有一个名为"BootstrapButton"的样式,可以通过`Style="{StaticResource BootstrapButton}"`将按钮的样式关联到它。


