无法找到目标元素的控制 FrameworkElement 或 FrameworkContentElement。GradientStop。

3

我有一个列表框,其中包含颜色,每种颜色都有7个打印头可供选择。因此,我的绑定变量是当选择打印头时,颜色框应该具有这些样式。

<Setter TargetName="colorSelectionRectangle" Property="Fill">
 <Setter.Value>
     <LinearGradientBrush SpreadMethod="Repeat" StartPoint="0,0" EndPoint="25,25">
         <LinearGradientBrush.RelativeTransform>
             <ScaleTransform ScaleX="0.01" ScaleY="0.01" />
         </LinearGradientBrush.RelativeTransform>
         <GradientStop Offset="0" Color="White" />
         <GradientStop Offset="0.5" Color="White" />
         <GradientStop Offset="0.5" Color="{Binding [0].Item.PrintColor.Argb}" />
         <GradientStop Offset="1" Color="{Binding [0].Item.PrintColor.Argb}" />
     </LinearGradientBrush>
   </Setter.Value>

我的错误是:

System.Windows.Data 错误:2:无法找到目标元素的主控 FrameworkElement 或 FrameworkContentElement。 BindingExpression: Path=[0].Item.PrintColor.Argb; DataItem=null; 目标元素为 'GradientStop' (HashCode=52327179); 目标属性为 'Color'(类型为 'Color')


1
你能提供更多细节吗?例如,您正在样式化的实际元素以及绑定中使用的模型的性质。 - meilke
1个回答

1

我相信您遇到这个问题是因为GradientStop不是FrameworkElement... 来自MSDN:

System.Object 
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Freezable
        System.Windows.Media.Animation.Animatable
          System.Windows.Media.GradientStop

如果您注意到上面的扩展System.Windows.Freezable类,则会发现该类也是“可冻结的”... 这意味着它无法被修改。有关更多信息,请参见MSDN上的Freezable Objects Overview页面。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接