动态添加交互行为

时间:2019-03-18 16:20:23

标签: c# wpf xaml

我的MainWindow.xaml文件中包含以下代码:

<dxmvvm:Interaction.Behaviors>
    <dx:DXSplashScreenService SplashScreenType="local:LoadingSplashScreen" ShowSplashScreenOnLoading="True"/>
</dxmvvm:Interaction.Behaviors>

我需要能够从codebehind(MainWindow.xaml.cs)动态添加此代码。这可能吗?

我需要使用Interaction.GetBehaviors(yourElementName).Add(behavior)吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以添加赞,

var splashScreenService = new DevExpress.Xpf.Core.DXSplashScreenService 
                              { 
                                  SplashScreenType = typeof(LoadingSplashScreen), 
                                  ShowSplashScreenOnLoading = true 
                              };
DevExpress.Mvvm.UI.Interactivity.Interaction.GetBehaviors(yourElement).Add(splashScreenService);