【问题标题】:Cannot find governing FrameworkElement or FrameworkContentElement for target element. GradientStop找不到目标元素的管理 FrameworkElement 或 FrameworkContentElement。渐变停止
【发布时间】:2013-08-22 03:36:18
【问题描述】:

我有一个包含颜色的列表框,每种颜色都有 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;数据项=空;目标元素是'GradientStop' (HashCode=52327179);目标属性是“颜色”(输入“颜色”)

【问题讨论】:

  • 你能提供更多细节吗?例如,您正在设计的实际元素以及绑定中使用的模型的性质。

标签: wpf


【解决方案1】:

我相信你有这个问题,因为GradientStop 不是来自 MSDN 的 FrameworkElement...:

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 页面。

【讨论】:

    猜你喜欢
    • 2016-06-02
    • 2021-08-22
    • 2020-02-10
    • 1970-01-01
    • 2013-03-24
    • 2013-08-17
    • 2013-06-09
    • 2014-02-03
    相关资源
    最近更新 更多