在“SetterCollectionBase"之后正在使用(密封),不能修改 [英] After a "SetterCollectionBase" is in use (sealed), it cannot be modified

查看:41
本文介绍了在“SetterCollectionBase"之后正在使用(密封),不能修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<UserControl x:Class="FlowItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300">
<UserControl.Resources>
    <Style TargetType="Label">
        <Style.Setters>
            <Setter Property="Background" Value="AliceBlue" ></Setter>
        </Style.Setters>
    </Style>
</UserControl.Resources>
<DockPanel Height="300" Width="300" LastChildFill="False" Background="Transparent">
    <Label Height="28" DockPanel.Dock="Top"></Label>
    <Label Height="28" DockPanel.Dock="Bottom">What ever</Label>
    <Label Width="28" DockPanel.Dock="Left"></Label>
    <Label Width="28" DockPanel.Dock="Right"></Label>
</DockPanel>

如何通过样式设置标签的背景?谢谢!

How could I set the Labels' Backgrounds via Styles? Thanks!

推荐答案

实际错误告诉我 Setter.Seal() 正在 setter 上被调用,并且稍后正在从该集合中添加或删除项目(即添加,插入、删除或清除被调用).我在您的 XAML 中看不到任何会导致这种情况的内容,并且代码对我来说编译得很好.

The actual error tells me that Setter.Seal() is being called on the setter and later items are being added or removed from that collection (ie. Add, Insert, Remove, or Clear was called). I can't see anything in your XAML that would cause that, and the code compiles fine for me.

我创建了一个空的 VS2008 C#WPF 应用程序"项目,将您的 XAML 作为一个没有代码的松散 XAML 文件添加到其中,并在最后添加了缺少的标签.生成的项目编译良好,我可以将 UserControl 添加到窗口中并查看.

I created an empty VS2008 C# "WPF Application" project, add your XAML to it as a loose XAML file with no code behind, and added the missing tag at the end. The resulting project compiles fine, and I can add the UserControl to the window and see it.

尝试使用相同的程序.如果它在空项目中有效但在您的项目中无效,请比较项目以找出导致问题的原因.以下是一些需要检查的事项:

Try using the same procedure. If it works in an empty project but not in yours, compare the projects to find what is causing your problem. Here ar some things to check:

  • 这些项目是否有相同的参考文献?
  • 项目是否具有相同的构建设置,包括目标框架?
  • 您的常规项目是否在任何地方使用UserControl"、Style"、Setter"等术语?
  • 如果您将代码隐藏起来,您的常规项目是否会执行?

如果您的 XAML 甚至无法在从 C# WPF 应用程序模板创建的全新空项目中工作,请检查以下事项:

If your XAML doesn't even work in a brand-new empty project created from the C# WPF Application tempate, here are the things to check:

  • 您是否安装了 Beta 版软件(尤其是 VS.NET 或 NET Framework),或者您是否曾经安装过,如果有,是否将其完全删除
  • 尝试使用 MSBuild 编译您的项目,看看问题是否与 IDE 相关
  • 尝试下载一个使用样式的工作 WPF 项目并对其进行编译,例如 Kevin's Bag Of Tricks (sp?)
  • 作为最后的手段,请尝试重新安装 NET Framework,如果这不起作用,请使用 Visual Studio

这篇关于在“SetterCollectionBase"之后正在使用(密封),不能修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆