应用资源时,wpf应用程序显示错误 [英] wpf application is showing error when resource is applied
问题描述
这里是window1.xaml的代码:
< window x:class =Resource_tutor.Window1 xmlns:x =#unknown>
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns = http://schemas.microsoft.com/winfx/2006/xaml
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
xmlns:sys =clr-namespace:System; assembly = mscorlib
Title =Resource DemoHeight =300Width =300removed =Lime>
< window.resources>
< sys:string x:key =strHelloworldxmlns:sys =#unknown> Hello,world!
< stackpanel margin =10removed =Lavender>
< textblock text ={staticResource strHelloworld}fontsize = 56>
< textblock>只是另一个< textblock text ={staticResource strHelloworld}&g吨;示例但有资源
------------------------------------------------ --------------------
显示错误:
''xmlns'是重复的属性名称。 XML无效。 C
你有:
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns = http://schemas.microsoft.com/winfx/2006/xaml
xmlns :x = http://schemas.microsoft.com/winfx/2006/xaml
第二个xmlns =http://schemas.microsoft.com/winfx/2006/xaml是第一个的副本。您只能有一个根XML名称空间,它是没有任何后缀的xmlns。违规行重复下一个具有正确后缀的行(注意:x)
xmlns:x =http:// schemas .microsoft.com / WinFX的/ 2006 / XAML
sir ! i have developed a simple wpf application using static resources in textblocks and stackpanel .
here's code of window1.xaml:
<window x:class="Resource_tutor.Window1" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Resource Demo" Height="300" Width="300" removed="Lime">
<window.resources>
<sys:string x:key="strHelloworld" xmlns:sys="#unknown">Hello,world!
<stackpanel margin="10" removed="Lavender">
<textblock text="{staticResource strHelloworld}" fontsize="56">
<textblock>just another "<textblock text="{staticResource strHelloworld}">" example but with resources
--------------------------------------------------------------------
it is showing error:
''xmlns' is a duplicate attribute name. XML is not valid. C
You have:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
The secondxmlns="http://schemas.microsoft.com/winfx/2006/xaml"is a duplicate of the first. You can only have ONE root XML namespace which is the "xmlns" without any postfix. The offending line duplicates the next one which has the proper postfix (notice the :x)
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
这篇关于应用资源时,wpf应用程序显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!