gpt4 book ai didi

WPF ResourceDictionary StringFormat XamlParseException

转载 作者:行者123 更新时间:2023-12-04 05:03:44 24 4
gpt4 key购买 nike

我有一个定义了 Style 的 ResourceDictionary,它有一个 ControlTemplate 和一个 Binding StringFormat,如下所示:

<TextBlock Text="{Binding TotalCash, Mode=OneWay, StringFormat={}{0:N2}, FallbackValue=0.00}" />

我在本地运行,一切正常,但我在服务器上进行了构建和安装,当我启动任何使用 ResourceDictionary 的 WFP 屏幕时,出现以下异常:
System.Windows.Markup.XamlParseException: 'Unexpected token after end of markup extension.' Line number '224' and line position '148'. ---> System.Xaml.XamlParseException: 'Unexpected token after end of markup extension.' Line number '224' and line position '148'.
at MS.Internal.Xaml.Parser.MePullParser.<Parse>d__0.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<LogicStream_Attribute>d__6f.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_EmptyElement>d__14.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_PropertyContent>d__5f.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_NonemptyPropertyElement>d__42.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_PropertyElement>d__35.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementContent>d__4a.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_ElementBody>d__23.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<P_Element>d__7.MoveNext()
at MS.Internal.Xaml.Parser.XamlPullParser.<Parse>d__0.MoveNext()
at MS.Internal.Xaml.NodeStreamSorter.ReadAheadToEndOfAttributes()
at MS.Internal.Xaml.NodeStreamSorter.ReadAheadAndSortCtorProperties()
at MS.Internal.Xaml.NodeStreamSorter.MoveNext()
at System.Xaml.XamlXmlReader.Read()
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
--- End of inner exception stack trace ---
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)

我做了一些挖掘,并通过将 ResourceDictionary StringFormat 从 {}{0:N2} 更改为 N2 使其工作:
<TextBlock Text="{Binding TotalCash, Mode=OneWay, StringFormat=N2, FallbackValue=0.00}" />

以下工作放入了 UserControl:
<TextBlock Text="{Binding TotalCash, Mode=OneWay, StringFormat={}{0:N2}, FallbackValue=0.00}" />

我的问题是为什么相同的 StringFormat 在 UserControl 中工作而不是在 ResourceDictionary 中工作?我很高兴它正在工作,但想了解原因。

最佳答案

这是一个 WPF bug .

我猜您在开发机器上本地安装了 .NET 4.5(因为可能安装了 Visual Studio 2012),但没有安装在您的服务器上(只有 .NET 4)。因此,您的服务器没有微软在 .NET 4.5 中添加到 WPF 的错误修正。

关于WPF ResourceDictionary StringFormat XamlParseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15789673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com