WPF 样式的一个问题

code_long 2020-07-08 02:12:47
无法将类型为“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某一个属性值不对 麻烦帮忙看一下


<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>
...全文
356 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
_秦同学_ 2021-02-20
  • 打赏
  • 举报
回复
看上去样式和模板的写法并没有问题,只是 ControlTemplate 的定义在 Style 的下面,直接在 Style 中使用 StaticResource 引用 ControlTemplate 资源是引用不到的。
内容概要:LTK8319是一款单通道H桥有刷直流电机驱动器,工作电压范围为2.5V至12V,支持最高3.9A的峰值电流和2.5A的平均电流驱动能力,适用于小家电、玩具、电子锁、机器人等小型电动设备。该芯片通过两个逻辑输入(INA和INB)控制电机的正转、反转、停止与刹车,并支持PWM调速控制。集成欠压锁定(UVLO)、过温保护(TSD)及自动故障恢复功能,确保系统安全可靠运行。当INA和INB持续为低电平时,芯片进入低功耗休眠模式,显著降低静态功耗。采用ESOP-8封装,符合环保无铅标准。; 适合人群:电子工程师、嵌入式系统开发者、电机控制技术人员,以及从事小型机电产品研发的设计人员;具备基本电路知识和电机控制经验者更佳。; 使用场景及目标:①用于驱动小型有刷直流电机或步进电机的一个绕组,实现精确的方向与速度控制;②适用于电池供电设备中对功耗敏感的应用,利用休眠模式延长续航时间;③在电机启停频繁、负载波动大的场合,发挥其电流控制与保护机制优势,提升系统稳定性。; 阅读建议:此文档提供了详细的电气特性、功能逻辑表、保护机制与时序参数,建议结合典型应用电路进行硬件设计,并重点关注电源去耦电容选型、散热布局及PWM频率设置(不超过100kHz),以确保系统可靠运行。

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧