How to create Recent Documents History in C# in WPF Application - c#

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. And 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 MenuItems 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.

Related

Cannot create resx file for i18n

Still spinning up on Xamarin.Forms and C#.
Did some research and everything is telling me that to create my externalized strings file, I just right click on the directory, click New Item... then click on Resource file. The problem is that my list looks vastly different than the lists I'm seeing in the tutorials and doesn't include a Resource file. Here's my list:
So I'm not sure what to click to get a resource file. There's evidently some special stuff about it because I tried creating an empty file and naming it that and it was confused.
How do I create these i18n resource files in Xamarin?
Thanks.
As suggested by #Deczaloth, I added the C# desktop applications workload and that made the resources file available. Yet another fail from Microsoft.

Edit Windows Context Menu in the C#

I would like a particular type of file (eg. Namefile.ext2) read all the names preceded by a #
Sample contents of the file:
#nameone
#nametwo
#namethree
When I click the right mouse button on the ext2 file extension beyond the standard options (like: open, properties, etc ...) I would like to be:
contents of the file > nameone
nametwo
namethree
Then, select the item (eg. nameone) pass this parameter to my program running in the background / or services
Do you need to modify the registry somehow? I will be grateful for tips on how to achieve the desired effect.
What you are asking about is called 'shell extension'. Basically it requires some knowledge of COM objects programming, but .NET made things a bit easier in that matter.
Shortly: you have to develop a piece of code which will reads the file and generates menu items dynamically (which may be tricky but possible). That code needs to be registered in the system as COM object.
Before it starts working you have to associate file extension with COM object you created.
Perhaps this article can explaint it a bit more:
http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus

WPF Custom Chrome Window?

i have been trying to make something along the lines of this...
I have looked and looked and only found this article.
I am having trouble integrating this into my application. I just started WPF today, so i am learning. I have downloded the window.Shell dLL. What else do i need? Thanks!
If you are looking for a step-by-step guide on how to add this to your application I can give it a try; I just happened to need a bit of a brush-up for a small app, I liked this and gave it a try - it took me about 45 minutes to apply. Cool stuff actually!
First: Download the source application and extract it to your computer.
In it you will find three subfolders. One with the sample application, one named Microsoft.Windows.Shell, one named CustomChromeLibrary. Copy the latter two to the root folder of your project map, add them to your project map (add existing project) and, from your startup project, reference them.
Now open the Window you want to apply CustomChromeLibrary to. You need to change the root from
<Window>
to
<ccl:CustomChromeWindow>
, this is done by using this code as the document root:
<ccl:CustomChromeWindow
Title="YourWindowTitle" Height="268" Width="733" ResizeMode="CanResize"
x:Class="YourNamespace.YourWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
xmlns:ccl="clr-namespace:CustomChromeLibrary;assembly=CustomChromeLibrary"
xmlns:local="clr-namespace:YourNamespace"
>
Pay attention to the last three lines in the sample. These need to be updated to reference the correct libraries; the last one actually referencing to YOUR namespace.
Next you need to update the source code of your window as this is still a simple Window and you will receive an error from it.
Change this
public partial class YourWindow : Window
to this
public partial class YourWindow : CustomChromeLibrary.CustomChromeWindow
You are already half way there!
Next you just need to create the objects for your window (title bar etc.). This is wonderfully done in the sample project No. 5; I did really just copy it.
Take everything from
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome
...
to here
<!--min/max/close buttons-->
<ccl:CaptionButtons/>
Now you can fill your Window like this
<Grid>
The content of your Window goes here
</Grid>
And close the xaml like this
</Grid>
</ccl:CustomChromeWindow>
Now, if you try to run this you will receive another error. There are still three files missing:
The first one you need is a Microsoft file: CaptionButtonRectToMarginConverter.cs; you will also find it in the sample. Copy it to your project and add it (add existing file).
You need to make one change to it:
namespace YourNamespace
{ ...
instead of the sample's namespace.
Finally you need the two xaml files that create the buttons: GlassButton.xaml and GlassIcon.xaml; they can be found in the "Resources" subfolder (and are referenced as resource dictionaries in the xaml). Copy the whole subfolder to your project and add the two files to your project (add existing file).
Now you should finally be able to run your project.
Let's not forget this: Lots of kudos to gbahns, the author of the original article over at codeplex.com!
There are quite a few implementations you can find for a custom chrome.
Another helper library I've seen to one you linked is
MahApps.Metro
Read section 3. It can be setup with Nuget making it more easier to integrate for someone new.
Also section 3.3 3.4 3.5 talk about customising and expanding the MetroWindow control which gives you a custom chrome and also allows adding controls to the chrome title bar
Over in this stack overflow question:
How can I add a button to the WPF caption bar while using custom window chrome?
I was asking about how to insert buttons into the title bar of my Custom Window Chrome window. The xaml example might be enough to help you get going.
Other than that, I'm not sure what you are looking for.
Edit: The button style I have in that other post is a fairly simplistic button, but you should be able to replace it with any styling that you want.

Resource Folder VS Resx File

First, please note I am a Java developer, started C# just few weeks back. Here is my question, it is about Visual Studio IDE.
I am using visual studio ide 2008 to create C# projects. I opened a new windows application, added a picture box to the form and now ready to add an image to it. I clicked the small black arrow button in picture box and it opens a dialog where we can put images.
Now, the question comes. In my c# book, they add images using the first option "Local Resource". Anyway, since I have to add number of images, I selected the "Project Resource File" and added all the images to the folder at once. Now I am working smooth without any issue. But, I can see the "Form.resx" file is empty (in my book, they show that file contains all the image files).
I want to know whether what I have done is correct or not. Even though that file is empty, no errors in the program anyway. I don't know whether any issue will occur after the distribution, like missing resources (In Java it normally happens unless otherwise you put all the resources into a new 'Package' inside the project. That's one of reasons I selected the second option when adding the images). Please help!
Your resources will be in a file called Resources.Resx (I think) this can found in your Properties folder in your project file
http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx This link has some information about using Resources
Its better to add the files to the project resource if your going to need them on multiple forms in the project. If they are only going to be required by the current form, you might as well put them in the forms resource file

How to include code samples in a WPF/Silverlight Component example application

I am working on the example application for a WPF & Silverlight component. As is common with these sorts of example applications, I would like to show C#/Xaml code to the end-user to assist them with creating their own applications with this component.
As a visual example of what I am trying to acheive, see here: http://www.microsoft.com/maps/isdk/silverlight/
This is the Bing Maps SDK example application. Notice how each example there is a tab with "Show Me" - the example, and "Source Code". A screenshot is also included below:
The examples application needs to both compile the source and display the source for both WPF and Silverlight. I don't want to include the source twice, as if the source for an example updates, I want to recompile and the "Source Code" tab should display the updated code.
Consider a typical example may consist of 1..N files in a folder, e.g.
AllExamples/SomeExample
SomeExampleView.xaml
SomeExampleView.xaml.cs
SomeExampleViewModel
SomeExampleConverter
How can I configure my project/solution to pick these source files up and not only compile them, but also get the text to display in the examples app "source code" tab, with the minimum fuss and avoiding copy/passting into a separate file?
Any suggestions welcome :)
Naive solution. Just add post-build event to your project that copies your sources to output directory and your "source code" tab can just read and show these files.

Categories

Resources