2012-11-26 38 views
1

下面的XAML產生XamlParseException在運行時:WPF baml序列化錯誤?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib"> 
    <Grid> 
    <Grid.Resources> 
     <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary> 
      <TextBlock x:Key="{x:Type TextBlock}"> 
       <Run Text="Aaaa"/> 
      </TextBlock> 
      </ResourceDictionary> 
     </ResourceDictionary.MergedDictionaries> 
     <sys:String x:Key="aaa"></sys:String> 
     </ResourceDictionary> 
    </Grid.Resources> 
    <Border Child="{StaticResource {x:Type TextBlock}}"/> 
    </Grid> 
</Window> 

XamlParseException: '上缺少關鍵值 'TextBlock的' 對象'。行號「10」和行位置「20」。

我在做什麼錯?

+0

您是否使用XamlReader.Parse?如果是這樣,它在XamlPadX中工作嗎?如果是這樣,[這個問題](http://stackoverflow.com/q/6850713/21475)可能有關係。 – Cameron

+0

我只是用上面的XAML作爲主窗口運行應用程序:) – ControlFlow

回答

-1

鍵不能是類型,它們是字符串。

+0

請在回答這樣的問題之前學習一些WPF :))))) – ControlFlow

+0

所以學到了,我的道歉。我認爲設置TargetType會更具可讀性。 –