内容设置不止一次 [英] Content is set more than once
问题描述
在 Visual Studio 2013 中使用 WPF 时,我遇到了一个错误:
Whilst playing about with WPF in Visual Studio 2013, I have been presented with an error:
错误 2 多次设置属性内容".
Error 2 The property 'Content' is set more than once.
错误 1 属性内容"只能设置一次
Error 1 The property "Content" can only be set once
现在,首先.我转向谷歌以获取错误消息 &获得了链接到 StackOverflow 的最佳结果.
Now, first of all. I turn to google for the error message & got presented with a top results linking to StackOverflow.
包括 MSDN 帖子:
Including a MSDN post:
虽然看到基于原始海报代码的定制解决方案的信息集合,但我还没有遇到详细说明此错误原因的实际基本解决方案(XAML 新手)虽然这可能是多个报告问题的重复.我个人宁愿避免发布有问题的代码以获得量身定制的解决方案.我更愿意来这里询问社区原因,为什么新手 XAMP/WPF 开发人员可能会遇到此应用程序和解决方案 &没有那么多顶级,顶级最佳实践.而是来自更多 WPF/XAMP 开发人员的关于如何轻松识别解决方案并在未来继续进行更多调试步骤的建议
Whilst being presented with an informative collection of tailored solutions based on the original posters code, I have yet to come across an actual basic solution detailing the reasons of this error (XAML Novice) Whilst this may be a duplicate of multiple reported problems. I personally would rather avoid posting a problematic code to get a tailored solution. I'd much rather come here and ask the community reasons as to why a novice XAMP/WPF Developer might encounter this application and solutions & not so much top, top best practices. Rather words of advice from the more WPF/XAMP Developers on how to easily identify the solution and continue on with furter debugging steps in the future
为了论证:
<Window x:Class="WPFT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="197.198" Width="427.95">
<TextBlock>Hello</TextBlock>
<TextBlock>World</TextBlock>
</Window>
推荐答案
一个窗口只能包含 1 个元素.
A window can only contains 1 element.
在你的代码中
<Window x:Class="WPFT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="197.198" Width="427.95">
<TextBlock>Hello</TextBlock>
<TextBlock>World</TextBlock>
</Window>
你的窗口有 2 个文本块你应该尝试类似
your window have 2 textblock u shoudl try something like
<Window x:Class="WPFT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="197.198" Width="427.95">
<Grid>
<TextBlock>Hello</TextBlock>
<TextBlock>World</TextBlock>
</Grid>
</Window>
这篇关于内容设置不止一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!