|
Hi,
I am working on WPF stack panel. In this I used to add items dynamically to the stack panel. Now If I click on the stackpanel item some message like the number of the child clicked should be displayed. Will there be any events for thi to checking the selected item of the stack panel.
If any one have any idea how to do this please reply me.
Thanks in advance
|
|
|
|
|
This might be somewhat complex.
Have a custom Routed event for the Canvas items.
Let the Canvas subscribe to this event.
The Canvas item fire's the routed event whenever it is selected.
When fired, the Canvas event handler gets invoked
In the handler, RoutedEventArgs parameter's OrignalSource property should give you the actual Canvas item that invoked the event.
|
|
|
|
|
Hi All,
I'm having a nightmare getting some XAML snippets adequately formatted for a new CP article. Anyone got any tips / working methods / tools that make this process easier?
Cheers,
|
|
|
|
|
I use Scrubber in MoXAML PowerToys[^] and the appropriate source language in the article template to accomplish this.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Nice ...
|
|
|
|
|
I like it. The next version of MoXAML has something called Babelcode - it converts from VB.NET to C#, and vice versa.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Now that will be a wicked addition to the tool set. I really must get VS Standard or Pro for me at home. I so miss MoXAML at home with C# Express.
|
|
|
|
|
Hi,
i have a UserControl (CustomToolbar) with buttons like new, delete, ...
Also i have a UserControl (Customer) with Textboxes, Labels, ...
My UserControl (Customer) looks like this:
<UserControl x:Class="test.ucCustomer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:mekoOffice">
<local:bDockPanel>
<local:ucCustomToolbar x:Name="tbCustomer" DockPanel.Dock="Top" />
<local:ucStatusbar x:Name="stMain" DockPanel.Dock="Bottom" />
<Grid x:Name="grdMain">
If i click on the button new in my toolbar the new-method in UserControl (Customer) should be fired. In another scenario if i click on the button new in my toolbar the new-method in UserControl (Article) should be fired. How can i accomplish that.
thx,
zauberfisch
|
|
|
|
|
You need to have the button call a method which works out which of your two methods to call, and branches from there. OR you can reset the event handler every time, but the first way makes more sense
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
That Toolbar should be kind of generic. It should be used in all kind of different UserControls. Do you have an example?
thx,
zauberfisch
|
|
|
|
|
You could do this quite easily with a RoutedEvent. Alternatively, you could look into MVVM, and take a look at integrating the Mediator pattern with this here.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Can you give me an example with a RoutedEvent, i get crazy because i don't understand how it works.
|
|
|
|
|
Pass the control with the buttons in it into the other controls, and subscribe to its button click events. This violates basic OOP principles, but if that's what needs to be done to process events, then so be it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
This sounds like a good scenario for Commands. You can make your button trigger the pre-defined New command like so:
<pre><Button Command="New">Click Me</Button></pre>
Then you can wire up a command binding anywhere up the visual chain from the toolbar to handle the New command. That handler will need to be able to determine which control method to call (which is basically CG's first suggestion).
|
|
|
|
|
Hi, I need make any animation of sound for my WPF aplication. I don't know how to get any data for my animation. Maybe intensity from left and right canal? I don't know how to get this data. Can anybody help me? Thanks
|
|
|
|
|
Yes, balance and volume are about the only things you could animate.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I searched articles on this site, this forum, and MSDN and could not find an answer, even though the actual code is probably very simple. How do I perform a lossless 90 degree rotation to a JPEG file using strictly WPF API's? I've seen code for using GDI+ only. I can't believe I have to step out of WPF to do this. I also need to preserve metadata.
I'm already accomplishing this with lossy compression but to minimize artifacts I have to set quality at maximum and this is doubling the size of my images.
|
|
|
|
|
There is no such thing as lossless JPEG compression, unless you use a JPEG format which .NET does not support. Therefore, you need a third party library to support lossless JPEG, JPEG 2000, etc. If you're starting with a JPEG, then your image is lossy to start with, and a 90 degree rotation should not cause a great amount of additional loss.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: There is no such thing as lossless JPEG compression
You're absolutely right about that, but what I was asking about is how to rotate a JPEG or HD Photo image without doing another round of compression. If a JPEG file is rotated in 90 degree increments, theoretically it is possible to rotate it losslessly, and all self-respecting software does this.
I thought this was fairly well known information. In a previous application of mine that used GDI+ instead of WPF, you could rotate and save an image 100 times without the slightest image degradation. There's just got to be a way of doing this with WPF as well.
Conceptually what you have to do is separate the image data from the metadata and do a block by block transformation of the image data without going through the compression algorithm. But I just don't know the right calls to make in WPF to do all this heavy lifting for me. I don't think there's any way to do this if you start with the TransformBitmap and RotateTransform classes.
|
|
|
|
|
OK - given that an image exists in memory as pixel data, and not as JPEG compressed data, I'd have assumed that any rotation is lossless in memory, but that you need to apply JPEG compression in order to save the image. You're saying this is not the case ? How odd.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: given that an image exists in memory as pixel data, and not as JPEG compressed data
This assumption is wrong, that's your conceptual mistake. There has to be a way of reading the image data into memory intact, without using a decoder. Then you do the bit-twittling necessary to transform the raw image data. Nothing is ever decompressed or compressed in this process.
Christian Graus wrote: but that you need to apply JPEG compression in order to save the image
You're thinking in terms of the very classes that I said cannot be used.
Christian Graus wrote: You're saying this is not the case ? How odd.
That's precisely what I'm saying, and it's not so odd if you understand what I'm talking about. Evidentally you've never heard of lossless JPEG rotation, but what do you think Photoshop does, or any other self-respecting image processing software?
I mean if I have to go to GDI+ to accomplish this, I'll do it, but that would really rub me the wrong way. I didn't sign up to WPF to go outside of it every time I turn around.
modified on Wednesday, June 10, 2009 4:01 PM
|
|
|
|
|
fjparisIII wrote: This assumption is wrong, that's your conceptual mistake.
Well, no. Once your image is in a bitmap, it's raw data, it's not JPEG compressed.
fjparisIII wrote: There has to be a way of reading the image data into memory intact, without using a decoder.
OK, I get it now. You rotate it, as a JPEG, in memory, not as a bitmap. Thus keeping the artefacts you have, but not creating new ones ?
fjparisIII wrote: Evidentally you've never heard of lossless JPEG rotation, but what do you think Photoshop does, or any other self-respecting image processing software?
I was aware they did that, but I'd never taken the time to wonder what it meant. I believe the Atalasoft library we use for DICOM compression offers what you're talking about.
fjparisIII wrote: I mean if I have to I'll go to GDI+ to accomplish this, I'll do it, but that would really rub me the wrong way. I didn't sign up to WPF to go outside of it every time I turn around.
I wrote a program in WPF, it's basically an image viewer. Our images are huge, and memory management in WPF is a joke ( in fact, we hard reset the GC regularly, or WPF just flat out dies ). So, when we load images from our DB, we resize them to the size of the screen, and then reload as we zoom, to save memory. We have two types of image, illustrations that are pngs, and photos that are jpgs. I don't know if it's the format, or the type of data, but our jpegs, when resized, would get all sorts of horrible artefacts. I was a Microsoft MVP at the time, so I theoretically had a fast track to support. I reported this, they responded that there was no problem. I sent a sample app to show the issue, got the same response. I wrote back and insisted, they finally looked at it and admitted it was broken. This was .NET 3.0, two years ago. The bug is still there, and WPF still does not expose Dispose methods, or clean up after images properly. So, get used to horrible imaging support in WPF. We resize our images using GDI+.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: You rotate it, as a JPEG, in memory, not as a bitmap. Thus keeping the artefacts you have, but not creating new ones ?
Exactly. Now you get it.
Regarding your WPF application that resizes images to fit the display, my application does the same thing. I don't know if you'd call my images huge (they're from 12 MPixel Nikon cameras, so 4288x2848), but WPF scales them in about two seconds.
Are you using the CroppedBitmap class to do this? I don't bother with this. Instead I just set the Margin property of the Grid object that holds the System.Windows.Controls.Image object that lives inside the grid. It works pretty well. I even use the same technique for zooming around an image at 1:1. The margin just propagates down to the image. I never touch the original bitmap once it decoded. I just let WPF worry about it and since WPF goes directly to DirectX it's pretty fast.
In fact one of my beta testers (actually pre-alpha) is amazed by how fast my new app based on WPF rotates images compared to the original C++/MFC app that used GDI+, which I guess goes through gobs of layers. My new app basically rotates an image instantly even on his slow machine, whereas my original GDI+ app takes a couple seconds on his machine.
I also support saving resized images to disk. I haven't noticed the "horrible artifacts" that you report. I'm using .NET 3.5.
I'm also somewhat disconcerted by the lack of low level control over garbage collection under .NET, especially since my app offers batch operations that can process thousands of images in a background thread. But it seems to do okay, not really any worse than my original C++ app based on GDI+.
What I've found is that the time to load a program can be a problem if it needs dozens of pages it has to render during startup. It's that JIT compiling that's the bottleneck. I'm still in pre-alpha testing so I'm not too worried about performance yet, but eventually I'll have to load pages on a demand basis so that the app displays instantly, instead of rendering all 70 pages that are in the app currently before it gives control to the user. On my 64-bit machine with 8 GBytes of RAM, the program displays in 2 seconds, but on my beta tester's machine with 1 GByte of RAM, it takes 30 seconds to render the app. Ugh!
Where WPF really shines and blows old rendering technologies away is individual image processing operations: displaying (say) an image that is 1920x1440 on a monitor that size is instantaneous, whereas with my old C++ app using GDI+ it would take a couple seconds to render such an image.
There's huge promise in WPF. I just hope Microsoft doesn't give up on it.
modified on Wednesday, June 10, 2009 5:01 PM
|
|
|
|
|
fjparisIII wrote:
Are you using the CroppedBitmap class to do this? I don't bother with this. Instead I just set the Margin property of the Grid object that holds the System.Windows.Controls.Image object that lives inside the grid. It works pretty well. I even use the same technique for zooming around an image at 1:1. The margin just propagates down to the image. I never touch the original bitmap once it decoded. I just let WPF worry about it and since WPF goes directly to DirectX it's pretty fast.
Yeah, we did that. But, our images are actually bigger than that, and as the use of our app means swapping images a lot, WPF basically would crap out and crash in time. Initially, it worked great, we moved to this to try to get out of memory issues.
fjparisIII wrote: I also support saving resized images to disk. I haven't noticed the "horrible artifacts" that you report. I'm using .NET 3.5.
I just ran my test app, the one I sent Microsoft, and it still happens. Radiographs were the images that showed it the worst, others, you had to look for. Also, it only happens on certain resizings, that is, you could resize several times before suddenly it would go bad. My test app remembers a setting that destroyed this particular picture, and applies it every time.
fjparisIII wrote: I'm also somewhat disconcerted by the lack of low level control over garbage collection under .NET, especially since my app offers batch operations that can process thousands of images in a background thread. But it seems to do okay, not really any worse than my original C++ app based on GDI+.
If you ever find that your app crashes, just ask, I'll post the code to fix that. In fact, I'll post it on my new blog some time soon, anyhow.
fjparisIII wrote: What I've found is that the time to load a program can be a problem if it needs dozens of pages it has to render during startup.
Yeah, and WPF is so slow to load to start with, we use a Win32 app as our splash screen, b/c otherwise it just was not responsive, it took ages to appear.
fjparisIII wrote: On my 64-bit machine with 8 GBytes of RAM, the program displays in 2 seconds, but on my beta tester's machine with 1 GByte of RAM, it takes 30 seconds to render the app. Ugh!
Yeah, we have users with 256 MB, although we say 512 is the minimum. I HAVE been pleasantly surprised at how the app performs on notebooks with shared video, I expected that to be a non starter.
fjparisIII wrote: There's huge promise in WPF. I just hope Microsoft doesn't give up on it.
I believe WPF is what they wanted Winforms 1.0 to be. I doubt they will give up on it. I agree, it has a lot of promise, and certainly the apps we write with it are way cooler than anything we could easily do in Winforms.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi
I'm trying to create a 3D modeling app in WPF, my app reads values from a database and generates 3D models based on the dimensions read out from the database, everything works fine, except for my models looking a bit dull. Also, when I rotate the camera at a certain angle, I can't differentiate between the different models because they overlap and there's no clear distinction between them, as they're all the same color.
I've tried playing around with specular materials as well as different kinds of lighting, but I can't seem to get it right.
If anyone has already created a similar application, or any application where you worked with 3D models, please help me find the correct combination of materials and lighting.
|
|
|
|
|