【发布时间】:2018-04-12 11:53:36
【问题描述】:
1) 我在使用 dx:LoadingDecorator 时遇到了一些性能问题,以证明我创建了一个小型示例应用程序。所以问题是每次我显示加载启动屏幕时,都会在可视树中推送一个 LoadingDecorator 的新实例,在内存中分配它并且永远不会被释放。在下一次运行时,将创建一个新实例。这种行为会导致内存泄漏。
xaml 代码是:
<dx:DXWindow x:Class="DXApplication12.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
Title="MainWindow" Height="800" Width="1525">
<Grid>
<dx:SimpleButton Width="100"
Height="20"
Content="Command"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Command="{Binding SimpleButtonCommand}"/>
<dx:LoadingDecorator
VerticalAlignment="Center"
HorizontalAlignment="Center"
IsSplashScreenShown="{Binding IsBusy}">
<dx:LoadingDecorator.SplashScreenTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="Loading ..." FontSize="30" Background="Transparent"/>
</StackPanel>
</DataTemplate>
</dx:LoadingDecorator.SplashScreenTemplate>
</dx:LoadingDecorator>
</Grid>
以及背后的代码:
public partial class MainWindow : DXWindow
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowViewModel();
this.ContentRendered += (s, e) =>
{
for (int i = 0; i < 1000; i++)
{
(this.DataContext as MainWindowViewModel).SimpleButtonCommand.Execute(null);
}
};
}
}
public class MainWindowViewModel : ViewModelBase
{
public ICommand SimpleButtonCommand => new DelegateCommand(() => {
this.IsBusy = true;
this.IsBusy = false;
});
private bool _isBusy;
public bool IsBusy
{
get => this._isBusy;
set => this.SetProperty(ref this._isBusy, value, nameof(this.IsBusy));
}
}
2) 另一个方面是,应用程序随机引发运行时异常: PresentationFramework.dll 中出现“System.InvalidOperationException”类型的未处理异常 此 Visual 未连接到 PresentationSource。
只有在使用 Visual Studio 启动应用程序时才会发生这种情况,如果我禁用 XAML 的 UI 调试工具,问题就会消失,但我认为这是一种解决方法,我想知道根本原因 :)
我还附上了一张照片来描述我遇到的两个问题:https://ibb.co/iJ057H
谢谢。
【问题讨论】:
标签: c# .net wpf devexpress desktop-application