How to create Recent Documents History in C# in WPF Application
I am making a WPF Application in C# where I need to show the recent documents history (just like it happens in word, excel and even visual studio), showing the list the last 5 or 10 documents opened. I have absolutely no idea as to how I should go about it. Please help. An开发者_开发知识库d please be kind and gentle...I am an amatuer coder, and it is tough to digest high-tech talks as of now! :)
JumpList in WPF4 is awesome. This was all I needed to do:
<Application
x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<Application.Resources>
</Application.Resources>
<JumpList.JumpList>
<JumpList ShowRecentCategory="True"/>
</JumpList.JumpList>
</Application>
This has a pretty nice walk through and sample
http://www.codeproject.com/KB/WPF/RecentFileList.aspx
Its good that it has both an xml file and registry store.
My idea of solving this problem (as a beginner) was to retain all the file paths into a Queue of given maximum capacity and adding them at run-time into a menuItem...
You could just keep a list of the documents that the user opens. Store the list when the program exits and load it when the program launches. You could probably store a list of things in the program settings, or you could write it to a file (plain text or xml would work ok).
You'd have to create the submenu for "recent documents" dynamically by keeping a reference to the "recent documents" MenuItem
, then adding and removing MenuItem
s from its Items
collection. There's a discussion about that here: Add new menuitem to menu at runtime.
The library that was linked above by Shoban looks like a set of classes that do this for you. But, it's for winforms. If you're using wpf, you might have to write your own (though there are probably pre-made ones out there somewhere), but the winforms one will give you a good starting place.
You can also then create jumplists in win7's taskbar using the Windows API Code Pack for .Net.
Gagan, i have recently made a recent file menu in WPF C# and here is what i did:
-> to enable the jumplist functionality and start menu recent file menu i used the windows API shell routine like this:
[DllImport("shell32.dll")] //shell routine to enable jumplist and recenfiles public static extern void SHAddToRecentDocs( UInt32 uFlags, [MarshalAs(UnmanagedType.LPWStr)] String pv);
and call it like this: SHAddToRecentDocs(0x00000003, mFilePath);
-> Then to display recent file menu i used an xml file, stored recent files in that and parsed and displayed recent file in the menu.
You might be interested in the Writer sample application of the WPF Application Framework (WAF). It shows how to use and implement a recent file list which is shown in the file menu and on the start page.
精彩评论