应用资源时,wpf应用程序显示错误 [英] wpf application is showing error when resource is applied

查看:92
本文介绍了应用资源时,wpf应用程序显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生!我已经使用textblocks和stackpanel中的静态资源开发了一个简单的wpf应用程序。

这里是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 second

xmlns="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屋!

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