Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF中样式定义的转换错误_C#_Wpf_Xaml - Fatal编程技术网

C# WPF中样式定义的转换错误

C# WPF中样式定义的转换错误,c#,wpf,xaml,C#,Wpf,Xaml,我正在编写以下代码。。当然,解决方案会生成并编译所有这些内容,但当我点击F5或start时,会收到以下错误消息 无法将属性“Style”中的值转换为类型为“System.Windows.Style”的对象。只能基于目标类型为基类型“矩形”的样式。标记文件中对象“System.Windows.Shapes.Rectangle”处出错 代码如下: <Style x:Key="Connector1" TargetType="Rectangle" BasedOn="{StaticResour

我正在编写以下代码。。当然,解决方案会生成并编译所有这些内容,但当我点击F5或start时,会收到以下错误消息

无法将属性“Style”中的值转换为类型为“System.Windows.Style”的对象。只能基于目标类型为基类型“矩形”的样式。标记文件中对象“System.Windows.Shapes.Rectangle”处出错

代码如下:

   <Style x:Key="Connector1" TargetType="Rectangle" BasedOn="{StaticResource Style123}">
    <Setter Property="Fill" Value="Aqua"  />
</Style>
<Style x:Key="Connector1_DragThumb" TargetType="Rectangle" BasedOn="{StaticResource Style123}">
    <Setter Property="IsHitTestVisible" Value="true"/>
    <Setter Property="Fill" Value="Yellow"/>
    <Setter Property="Stroke" Value="Black"/>
</Style>

感谢您的帮助


关于。

错误表明,此样式所基于的
StaticResource Style123
本身没有
TargetType=“Rectangle”


您只能将一个
矩形
样式基于另一个
矩形
样式或其基类(或使用
{StaticResource{x:Type Rectangle}}
的默认值)。

您的上一条语句不正确。要求样式的
TargetType
等于或源自
BasedOn
样式的
TargetType
<代码>形状可以工作例如Hi Jay,谢谢。。。我知道了,而且很好用。现在,我知道它是如何工作的,但是用户控制呢?如何处理用户控件以达到相同的目的?嗨,Meleak,抛出错误的原因是style123用于路径,例如,因此我创建了另一个应用于矩形的样式。这就解决了问题。