我尝试使用以下样式将ContextMenu应用到所有文本框中,以便共享。
<Grid.Resources>
<Style x:Key="Cell" TargetType="TextBox">
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0.2"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="MinHeight" Value="30"/>
<Setter Property="MinWidth" Value="70"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Level1" Click="SubLevel1_Click_1"/>
<MenuItem Header="SubLevel1"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
在添加点击事件之前,此代码运行良好。添加点击事件后,它可以构建但在执行时会抛出以下异常: “设置connectionId时引发了异常。” 行号 '21' 和行位置 '34'。
我在这里做错了什么?