我对窗口的行为如下所示
<Window>
<my:Notify x:Name="Not"/>
<behaviors:Interaction.Behaviors>
<behavior:RebuildBehavior Element="{Binding ElementName=Not}" />
</behaviors:Interaction.Behaviors>
<Window>现在我想用后面的代码编写这段代码,所以我使用了以下代码:
在Notify.cs (加载事件)中:
RebuildBehavior behavior = new RebuildBehavior();
behavior.Element = this;
Interaction.GetBehaviors(this).Add(behavior);但是我的应用程序崩溃在最后一行Interaction.GetBehaviors(this).Add(behavior);
System.Resources.MissingManifestResourceException:‘
无法在资源中找到"ExceptionStringTable.resources“资源
我写的代码正确吗?
更新:我将代码移到window.cs (加载事件)
RebuildBehavior behavior = new RebuildBehavior();
behavior.Element = Notify.Instance;
Interaction.GetBehaviors(this).Add(behavior);故障修复但不起作用
发布于 2021-11-12 14:07:18
以下代码相当于您的XAML标记:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
RebuildBehavior behavior = new RebuildBehavior();
BindingOperations.SetBinding(behavior, RebuildBehavior.ElementProperty,
new Binding() { ElementName ="Not" });
Interaction.GetBehaviors(this).Add(behavior);
}
}https://stackoverflow.com/questions/69939016
复制相似问题