[英]wpf binding user control loaded event no executed
我有一个带有加载事件的用户控件,当我将其包含在XAML中的内容控件中时,它会完美地执行加载事件。
但是,我已将其更改为对内容控件的动态绑定,现在不执行已加载的事件。
我的用户控件的标题:
<UserControl x:Class="DesignSuite.CanvasTools.DrawCanvas"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:my="clr-namespace:DesignSuite.CanvasTools" Loaded="UserControl_Loaded">
我使用模板通过以下方式绑定contentcontrol:
<DataTemplate x:Key="FiniteStateMachineCanvasContentTemplate">
<ContentControl Content="{Binding FiniteStateMachineCanvas}"/>
</DataTemplate>
继承内容控件的Canvas显示正常,仅不执行已加载的事件。
绑定的代码是:
public DrawCanvas FiniteStateMachineCanvas { get; set; }
public FiniteStateMachineCanvasTab (
string NewName,
ref Toolstate toolstatemanager,
ref FiniteStateMachineDescriptor finiteStateMachineDescriptor)
{
HeaderText = NewName;
FiniteStateMachineCanvas = new DrawCanvas(ref toolstatemanager, canvastype_e.CANVAS_FINITESTATE, ref finiteStateMachineDescriptor);
}
有没有人朝着正确的方向发展?
解决了
忘了在我创建的新构造函数中执行InitalizeComponent,这就是问题的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.