を使用してXAMLをXamlReader読み込んでいますが、条件付き文字列形式を使用してデータバインドすると、読み込みに問題があります。構文エラーが発生していないことを確認するために、スタンドアロンのWPFアプリケーションで条件付き形式を試しました。これは、検証に使用するXAMLです。
<Window
  x:Class="WpfApplication.Window"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <TextBlock Text="{Binding Value, StringFormat={}{0:;#,##0.00;}}"/>
</Window>
そして、コードビハインド:
public partial class Window {
  public Window() {
    InitializeComponent();
    DataContext = this;
  }
  public Decimal Value { get { return -1234567.89M; } }
}
予想どおり、数値は負の符号なしで表示されます(値がゼロまたは正の場合は表示されません)。
ただし、次を使用してXAMLをロードしたいと思いますXamlReader。
var xaml = @"<TextBlock
  xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
  Text=""{Binding Value, StringFormat={}{0:;#,##0.00;}}""/>";
var textBlock = (TextBlock) XamlReader.Parse(xaml);
これTextBlockは同じですが、への呼び出しXamlReader.Parseは例外を除いて失敗します。
System.Windows.Markup.XamlParseExceptionが発生しました
  Message='マークアップ拡張の終了後の予期しないトークン。' 行番号「3」および行位置「40」。
  Source = PresentationFramework
  LineNumber = 3
  LinePosition = 40
  スタックトレース:
       System.Windows.Markup.XamlReader.RewrapException(Exception e、Uri baseUri)で
       System.Windows.Markup.XamlReader.Load(XmlReaderリーダー、ParserContext parserContext、XamlParseMode parseMode)で
       System.Windows.Markup.XamlReader.Load(XmlReaderリーダー)で
       System.Windows.Markup.XamlReader.Parse(String xamlText)で
       WpfApplication \ Window.xaml.cs:line 17のWpfApplication.Window..ctor()で
  InnerException:System.Xaml.XamlParseException
       Message='マークアップ拡張の終了後の予期しないトークン。' 行番号「3」および行位置「40」。
       Source = System.Xaml
       LineNumber = 3
       LinePosition = 40
       スタックトレース:
            MS.Internal.Xaml.Parser.MePullParser.d__0.MoveNext()で
            MS.Internal.Xaml.Parser.XamlPullParser.d__6f.MoveNext()で
            MS.Internal.Xaml.Parser.XamlPullParser.d__14.MoveNext()で
            MS.Internal.Xaml.Parser.XamlPullParser.d__7.MoveNext()で
            MS.Internal.Xaml.Parser.XamlPullParser.d__0.MoveNext()で
            MS.Internal.Xaml.NodeStreamSorter.ReadAheadToEndOfAttributes()で
            MS.Internal.Xaml.NodeStreamSorter.ReadAheadAndSortCtorProperties()で
            MS.Internal.Xaml.NodeStreamSorter..ctor(XamlParserContextコンテキスト、XamlPullParserパーサー、XamlXmlReaderSettings設定、Dictionary`2 xmlnsDictionary)で
            System.Xaml.XamlXmlReader.Initialize(XmlReader giveXmlReader、XamlSchemaContext schemaContext、XamlXmlReaderSettings設定)で
            System.Xaml.XamlXmlReader..ctor(XmlReader xmlReader、XamlSchemaContext schemaContext、XamlXmlReaderSettings設定)で
            System.Windows.Markup.XamlReader.Load(XmlReaderリーダー、ParserContext parserContext、XamlParseMode parseMode)で
       InnerException:
{}{0:;#,##0.00;}あいまいな文字列形式を置き換えれば';#,##0.00;'、ロードは成功します。残念ながら、私が必要とする他の形式(正の値用の形式)は'#,##0.00;;'、値が負の場合、何らかの理由で条件付き形式として動作しません。(本来のように何も表示されないのではなく、負の数が記号で表示されます。「ブラケット」バージョンではこの問題は発生しません。)
だから私の質問はXamlReader.Parse、同じXAMLを使用してWPFアプリケーションを構築するときに、同じ条件付き文字列形式で問題がない場合にXAMLが読み込まれるときに、データバインディングで括弧付きの条件付き文字列形式を使用できないのはなぜですか?