Easy way to use Images in WPF
I've only just started using WPF. (I'm a WinForms guy), and from wh开发者_Python百科at I can see, trying to simply drag an image onto the Window is a huge PAIN. There seems to be no way where you can just select an option to tell it what picture to put indide the image control. I've seen so many sites within the last 10 minutes with atleast 10lines of code just to insert animage into a window. Is there an easier way?
First, I recommend you download an evaluation copy of Expression Blend instead of trying to do your development in Visual Studio. Blend is a far, far better tool for creating WPF UIs and it integrates beautifully with Visual Studio.
For example, in Blend, it is as simple as dragging an image onto the window. When you do so, Blend creates this XAML:
<Image Source="Photos/WashingtonMonument.jpg" />
That said, I have no idea why you're seeing examples that require 10 lines of code to do this! It seems ridiculous to me when one line of very simple XAML will suffice.
精彩评论