2
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="This is my text">
  <TextBlock>
    <Run Text="{Binding}"/>
  </TextBlock>
</Window>

スローInvalidOperationException: 「双方向バインディングにはパスまたは XPath が必要です。」

, を指定Mode=OneWayすると、奇妙なコンパイラ エラーが発生します。

The tag 'Binding,' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

これを修正するxamlyの方法はありますか?

4

2 に答える 2

3

理由はわかりませんが、ぎこちなくせずに行う方法は次のとおりです。

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    DataContext="This is my text">
  <TextBlock>
    <Run Text="{Binding Path=.}"/>
  </TextBlock>
</Window>

何らかの理由で

<Run Text="{Binding}" />

実行時エラーが発生しますが、

<Run Text="{Binding Path=.}" />

ではない。その理由は、バインディングが「あいまい」である場合に関係している可能性があります。バインディングを解釈するために引き継がれる特定のフォールバック動作があります。あるいは、これは、コントロール{Binding}上で解釈する本物の MS バグです。Run

于 2011-05-02T20:54:38.643 に答える
0

奇妙なworkarondを見つけました:

<Window
  x:Name="Me"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  DataContext="This is my text">
  <TextBlock>
    <Run Text="{Binding DataContext, ElementName=Me}"/>
  </TextBlock>
</Window>
于 2010-12-19T03:01:35.340 に答える