2015-06-04 18 views
0

我得到我的輸出面板具有約束力的錯誤,當我跑我的應用程序:費克斯綁定錯誤的風格結合應用

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Shapes.Ellipse', AncestorLevel='1''. BindingExpression:Path=Width; DataItem=null; target element is 'TranslateTransform' (HashCode=59715965); target property is 'X' (type 'Double')

我想創建一個適用於所有一個TranslateTransform風格畫布中的橢圓。綁定工作,但是當我開始我的應用程序,我得到我的輸出面板中的錯誤。我該如何解決這個錯誤?

編輯:綁定確實工作,我只是想擺脫在Visual Studio輸出窗口中的錯誤。

如果我將樣式中的RenderTransform移動到Ellipse標記中,則錯誤消失,但是我希望在該樣式中使用此轉換,因爲它需要應用於許多省略號。

這是我使用的XAML:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="WpfApplication1.MainWindow" 
     Title="MainWindow" Height="300" Width="300"> 
    <Window.Resources> 
     <Style TargetType="Ellipse"> 
      <Setter Property="RenderTransform"> 
       <Setter.Value> 
        <TranslateTransform> 
         <TranslateTransform.X> 
          <Binding 
            RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Ellipse}}" 
            Path="Width"/> 
         </TranslateTransform.X> 
        </TranslateTransform> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Window.Resources> 
    <Canvas> 
     <Ellipse Width="100" Height="100" Fill="Red" /> 
    </Canvas> 
</Window> 
+0

此代碼對我的作品。在這兩種情況下:Window.Resources和Ellipse.Resources VS2013 –

+0

我也使用VS2013,並且代碼可以正常工作,但在輸出窗口中出現奇怪的錯誤。運行代碼時,輸​​出窗口是否爲空? – Ove

+0

我只在窗口內部有紅色變換的橢圓。 –

回答