行。所以我有以下几行的主要观点
<!-- The first one is commented cause I tried it and it failed harder -->
<!--<ContentControl Name="BcModel" Grid.Column="2" Width="300" Height="300"/>-->
<local:BigCalendarDateView x:Name="BcModel" Grid.Column="2" Width="300" Height="300"/>
和 ViewModel
[Export(typeof(AppViewModel))]
public class AppViewModel : Screen
{
public BigCalendarDateViewModel BcModel { get; set; }
[ImportingConstructor]
public AppViewModel(BigCalendarDateViewModel mod, IEventAggregator events)
{
this.DisplayName = "Calendar";
events.Subscribe(this);
BcModel = mod;
}
}
对于BigCalendarDateViewModel
, 我有视图
<!-- Commented because I tried this also -->
<!--cal:Message.Attach="[Event Click] = [Action ChangeState]"-->
<Button Name="ChangeState" Content="Button" HorizontalAlignment="Left" Margin="76,156,0,0" Grid.Row="2" VerticalAlignment="Top" Width="138"/>
在 ViewModel 中
[Export(typeof(BigCalendarDateViewModel))]
public class BigCalendarDateViewModel : PropertyChangedBase
{
...
public void ChangeState()
{
Console.Beep();
}
}
我可以调试通过,AppView、AppViewModel、BigCalendarDateView和BigCalendarDateViewModel都被初始化了,BigCalendarDateViewModel直观地显示了,但是当我点击按钮时,它要么说找不到方法,要么什么都不做.
似乎 BigCalendarDateViewModel 从未连接到 BigCalendarDateView。
当我为控件创建一个引导程序时,它会在自己的窗口中弹出它,它工作正常(在新窗口中,而不是在第一个窗口中)
有任何想法吗?