2011-04-11 56 views
1

我需要一些幫助,我從自定義按鈕上的樣式獲得綁定錯誤。 這裏是XAML:WPF圖像效果控件模板中的綁定錯誤

<Style TargetType="{x:Type Controls:DropDownButton}" BasedOn="{StaticResource ButtonBaseStyle}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type Controls:DropDownButton}"> 
         <Border 
          x:Name="border" 
          Padding="{TemplateBinding Padding}" 
          HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
          VerticalAlignment="{TemplateBinding VerticalAlignment}"> 
          <Grid> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="*"/> 
            <ColumnDefinition Width="Auto"/> 
           </Grid.ColumnDefinitions> 

           <Grid Grid.Column="0" > 
            <Border Padding="5"> 
             <Grid> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="*"/> 
               <RowDefinition Height="*"/> 
              </Grid.RowDefinitions> 

              <Grid Grid.Row="0"> 
               <Image 
                Style="{StaticResource DefaultImageStyle}" 
                Source="{Binding SmallImage, Converter={StaticResource LocalizingConverter}}"> 
                <Image.Effect> 
                 <ShaderEffects:GrayscaleEffect 
                  DesaturationFactor="1" 
                  IsEnabled="{Binding IsEnabled, RelativeSource={RelativeSource TemplatedParent}}"/> 
                </Image.Effect> 
               </Image> 
              </Grid> 
              <Grid Grid.Row="1"> 
               <TextBlock 
                Style="{StaticResource DefaultTextHeaderStyle}" 
                Text="{Binding Name, Converter={StaticResource LocalizingConverter}}"/> 
              </Grid> 
             </Grid> 
            </Border> 
           </Grid> 
           <Grid 
            Grid.Column="1" 
            VerticalAlignment="Stretch"> 
            <Polygon                  
             x:Name="arrow" 
             Points="0,0 8,0 4,5"                                    
             Fill="{TemplateBinding Foreground}" 
             VerticalAlignment="Center" 
             HorizontalAlignment="Center"/> 
           </Grid> 
          </Grid> 
         </Border> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

,當應用程序啓動時給了我下面的綁定錯誤:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'GrayscaleEffect' (HashCode=4769001); target property is 'IsEnabled' (type 'Boolean')

的圖像效果似乎工作正常,但最新的成交與綁定錯誤我該如何解決它?

回答

1

我不認爲該效果實際上有一個DataContext,因爲它不從FrameworkContentElement繼承,所以它無法通過繼承的DataContext找到模板化的父級。我用Camera對象看過同樣的事情,它也沒有得到DataContext。查看:http://msdn.microsoft.com/en-us/library/system.windows.media.effects.effect.aspx

IsEnabled部件是否能正常工作?

+0

是的,當按鈕被禁用時,效果肯定會被應用。 – Sigh 2011-04-11 03:52:47