English 中文(简体)
C#/WPF: Display Images like a LightBox in jQuery?
原标题:

Did anyone ever try to create a jQuery "LightBox"-Like "Popup" (WPF UserControl) for displaying Images? See this page for an example: http://www.huddletogether.com/projects/lightbox2/

Thanks!

最佳回答

Here is a site that appears to have done it, but it is only version 0.5 and might change dramatically before 1.0:
http://leandrovieira.com/projects/jquery/lightbox/#

This should be what you re looking for, and here is a sample of their code to implement:

$(function() {
    $( #gallery a ).lightBox({fixedNavigation:true});
});

I hope this helps,

Thanks!


EDIT:

Sorry that I didn t fully understand what you ment in version one of your question. Here is an updated answer (with code / source) to your question.

First I created a control that will act as a modal dialog box that grays everything out in the background. Then I added the ability to put a picture in there, with added ability to have a comment with each picture. Here are images of the final product:

First Image Loaded: First Image Loaded http://img682.imageshack.us/img682/8941/firstpictureopen.jpg

Second Image Fading In: Second Image Fading In http://img5.imageshack.us/img5/3172/secondpicturefading.jpg

Second Image Loaded: Second Image Loaded http://img682.imageshack.us/img682/5404/secondpictureopen.jpg

I also added animations to resize the images like the Lightbox project does. I added the ability to have a forward and back buttons, accelerator keys, forward and back arrow control, and escape to exit. I think I ve captured what you re looking for in this control.

As usual, I ve uploaded the full source code to Google Code for your download.

The direct link to the zip file is here:
http://stackoverflow-answers-by-scott.googlecode.com/files/1755872.zip

I hope this helps,

Thanks!

问题回答

Duplicating the functionality you linked to is absolutely trivial in WPF. Just:

  1. Create a UserControl with a single ItemList property of type IEnumerable<ImageSource>
  2. Add a Popup to the UserControl
  3. Add a Grid to the Popup that lays out the LightBox the way you want, including panels for the Image, TextBlock, and Button
  4. Add a StoryBoard that is triggered by the Loaded event that animates the changes.
  5. Use an EventTrigger to set the Popup s IsOpen property to false when the button is clicked
  6. Bind the Image.Source to {Binding ItemList/} to show the current item in the ItemList
  7. Add a Background="Transparent" rectangle to each side of the Grid that runs code-behind to change the current item in ItemList
  8. Optionally also repeat the BeginStoryboard when changing the current item




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签