我在WPF
,MVVM
中有一个应用程序。显示Images
中ListBox
的列表,每个图片都与不同的会话相关联。
我的ListBox
ItemTemplate
看起来像这样,
<ListBox.ItemTemplate>
<DataTemplate>
<Image
Source="{Binding IsClaims,Converter={StaticResource PolicyClaimsImageSelector}}"
ToolTipService.ShowDuration="7000">
<Image.ToolTip>
<StackPanel>
<TextBlock Text="{Binding WorkingSessionName}" />
<Views:ToolTipView DataContext="{Binding ThisViewModel}"/>
</StackPanel>
</Image.ToolTip>
</Image>
</DataTemplate>
</ListBox.ItemTemplate>
我的ViewModel
public class Session : BindableBase
{
private MainViewModel _ThisViewModel;
public MainViewModel ThisViewModel
{
get
{
return _ThisViewModel;
}
set
{
_ThisViewModel = value;
NotifyPropertyChanged();
}
}
}
当工具提示出现时,存在内存泄漏,无法理解其发生的原因,
我的问题是,在显示ToolTip
之后,我有dispose
到ToolTip
任何记忆的任何内容吗?如果是这样怎么做?
修改
没有订阅任何活动。仅绑定不同DataContext
ViewModels
的{{1}}
ToolTipView.XAML
Views
我已尝试从 <DockPanel>
<xcad:DockingManager DockPanel.Dock="Left" Grid.Row="2" BorderBrush="Black" BorderThickness="1">
<xcad:DockingManager.Theme>
<xcad:MetroTheme />
</xcad:DockingManager.Theme>
<xcad:LayoutRoot >
<xcad:LayoutPanel Orientation="Horizontal" >
<xcad:LayoutAnchorablePaneGroup Orientation="Horizontal" DockMinWidth="150" >
<xcad:LayoutAnchorablePane >
<xcad:LayoutAnchorable Title="Folder" x:Name="ExplorerView" AutoHideWidth="300">
<Views:ExplorerView DataContext="{Binding ExplorerViewModel}"/>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
<xcad:LayoutAnchorablePaneGroup Orientation="Horizontal" DockMinWidth="450" >
<xcad:LayoutAnchorablePane >
<xcad:LayoutAnchorable Title="Documents" x:Name="TOC">
<Views:TableOfContentView DataContext="{Binding TableOfContentViewModel}"/>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
<xcad:LayoutAnchorablePaneGroup Orientation="Vertical" DockMinWidth="320">
<xcad:LayoutAnchorablePane DockMinHeight="400" >
<xcad:LayoutAnchorable Title="Properties" x:Name="Property">
<Views:PropertyView DataContext="{Binding PropertyViewModel}"/>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
<xcad:LayoutAnchorablePane >
<xcad:LayoutAnchorable Title="Search" x:Name="Search">
<Views:SearchPanel DataContext="{Binding SearchViewModel}"/>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
</DockPanel>
中移除所有Views
,如下所示,并显示工具提示,而ToolTipView.XAML
中的任何视图都给我相同的ToolTip
。< / p>
现在我的ToolTipView.XAML就是这样,
memory leak
答案 0 :(得分:0)
这在黑暗中有点刺,但可能有些尝试。我有一个问题,某些图形驱动程序会以某种方式触发WPF中的泄漏。我们最终禁用了WPF禁用硬件加速和重新测试。这不是一个理想的答案,但足以让我们为长期运营客户的客户解决问题。
在注册表中(系统范围内)
[HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics]
"DisableHWAcceleration"=dword:00000001
或通过应用程序本身的代码:
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
您可以使用&#34; WPF Performance Suite&#34;来测试通过软件或硬件呈现的内容。并为软件渲染元素启用紫色色调。
我希望这会有所帮助。
答案 1 :(得分:0)
我通过创建一个模仿实际绑定的接口修复了它。见下文。
.page-container
现在我使用ToolTipView绑定此属性,即:
Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim NamePath As String
Dim strName As String
Dim lFind As Long
If SaveAsUI = True Then' unless this is set to <> true, it does not work
Cancel = True
With Application
.EnableEvents = False
NamePath = .GetSaveAsFilename
strName = Mid(NamePath, InStrRev(NamePath, "\", -1, vbTextCompare) + 1, 256)
If NamePath = "False" Then' this is part of the code that confuses me
.EnableEvents = True
Exit Sub
ElseIf left(strName,6) <> "Lowpar" Then
MsgBox "You cannot save as another name"
.EnableEvents = True
Exit Sub
Else
Me.SaveAs NamePath
.EnableEvents = True
End If
End With
End If
End Sub
现在,当我们更改工具提示时,内存不会增长。