项目里面的代码比较多。我简单的写个demo,描述一下问题。
新建一个WpfApplication。添加一个Dictionary1.xmal。在里面添加下面代码,显示一个椭圆。
<Ellipse x:Key="ellipse" Fill="Yellow" ToolTip="Ellipse" IsHitTestVisible="false"/>
在App.xaml中引用Dictionary1。代码如下:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
然后在窗体2中使用这个ellipse,显示这个椭圆,代码如下:
<ContentControl FontSize="30" Content="{StaticResource ellipse}" Margin="0,0,0,12"/>
在窗体1中添加一个按钮,在click事件中打开窗体2。
第一次点击按钮,打开窗体2没有问题。
第二次点击按钮,打开窗体2有问题。报错
“设置属性“System.Windows.Controls.ContentControl.Content”时引发了异常。”,行号为“4”,行位置为“25”。