wpf-mvcdemo_介绍BabySmash-WPF实验

wpf-mvcdemo

wpf-mvcdemo

WPF (Windows Presentation Foundation) is confusing, to me at least. It's one of those things that is so completely different from how things were done in the past that it's not only hard to just pick up, but it's hard to tell what's the right way to do things. Often, there's a half-dozen ways to do something but no way to know which is the right. By right, I mean, most robust, most reliable, most future-proof, most supported, most compatible. It's powerful, but the power isn't immediately discoverable.

WPF(Windows Presentation Foundation)至少使我感到困惑。 这是与过去的工作方式完全不同的事情之一,不仅很难拾起,而且很难说出正确的做事方法。 通常,有六种方法可以执行某项操作,但无法知道哪种方法是正确的。 没错,我的意思是,最健壮,最可靠,最适合未来,最受支持,最兼容。 它功能强大,但功能无法立即发现。

一点个人历史 (A Little Personal History)

I'm a Win32 guy from way back. To be honest, I'm a Win16 guy. I cut my teeth when Hello World was 92 lines of C code on Windows 3.0, not counting the dialog resources. I worked on internationalizing applications in '95 when thunking (translating between 16 and 32-bit) was all the rage. We had an educational security application that needed to run in DOS, Windows 3.1 and Windows 95, and they wanted to re-use as much code as possible, so I #ifdef'd my way to glory.

我是Win32的老手。 老实说,我是Win 16球员。 在Windows 3.0上,Hello World是92行C代码时,我不屑一顾,没有计算对话框资源。 我在95年致力于国际化应用程序,当时风靡一时(在16位和32位之间转换)。 我们有一个教育安全性应用程序,需要在DOS,Windows 3.1和Windows 95中运行,他们想重复使用尽可能多的代码,所以我#ifdef走向了辉煌。

I not only understand Win32, but I understand it's historical context and many of the design decisions behind it. Certainly not as much as Raymond Chen, but I devoured Petzold's legendary book, as did we all, and when MFC came out, I understand exactly what it abstracted and what it didn't.

我不仅了解Win32,而且了解它的历史背景及其背后的许多设计决策。 当然不如Raymond Chen那样多,但是我和我们所有人一样,都吞噬了Petzold的传奇书,而当MFC问世时,我确切地理解了它的抽象和不抽象的含义。

WinForms is a managed layer over Win32 Windowing, and not only does Win32 sneak out occasionally in your code, but so does (of course) many other Win32 APIs.

WinForms是Win32 Windowing上的一个托管层,不仅Win32偶尔会在您的代码中潜行,而且(当然)许多其他Win32 API也是如此。

宝贝粉碎 (BabySmash)

OK, fast forward to this past weekend. My 2.5 year old and 6 month olds are constantly smashing on the various computers around the house. There's two Macs and four PCs in various locations. I've got a great free toddler-specific  application called AlphaBaby installed on the Mac that makes sounds, shows letters and numbers while ostensibly protecting the machine (the software at least) from the kids. When I see my kids playing with it with such enthusiasm, I always think of the Incredible Hulk when he says "Hulk! Smash!" so this is "Baby! Smash!"

好,快过去这个周末。 我的2.5岁和6个月大的孩子不断在家里的各种计算机上捣烂。 在不同位置有两台Macs和四台PC。 我在Mac上安装了一个很棒的免费幼儿专用应用程序AlphaBaby ,该应用程序可以发出声音,显示字母和数字,同时表面上保护机器(至少是软件)免受儿童的伤害。 当我看到我的孩子们如此热情地玩耍时,我总是想起不可思议的绿巨人,当他说“绿巨人!粉碎!” 所以这是“宝贝!粉碎!

I always wanted a Windows version of AlphaBaby, and some Googling didn't find me what I wanted, although I knew it must be out there. (Of course, now many of you have shared with me your favorite toddler programs. Someone should re-write KidPix for the PC. THAT was a great application.)

我一直想要Windows版本的AlphaBaby,尽管我知道它一定存在,但有些谷歌搜索找不到我想要的东西。 (当然,现在你们中的许多人已经与我分享了您最喜欢的蹒跚学步的程序。应该为PC重新编写KidPix。那是一个很棒的应用程序。)

学习WPF (Learning WPF)

My wife was watching some horrific movie on Lifetime (seriously, Patrick Swayze was in it and it wasn't Dirty Dancing) so I figured I'd spend a few hours and bang out a little application for the boys. Then I realized that this was a fine opportunity to learn WPF. I understand the general ideas behind WPF and Chris Sells has explained some aspects of it to me. Suffice it to say, WPF is a complete re-imagining of how Windows Client Developer should work - hence it's relative inaccessibility to folks like me who are deeply routed in PeekMessage. ;)

我的妻子正在看一生中的恐怖电影(严重的是,帕特里克·斯威兹(Patrick Swayze)在其中,这不是《肮脏的跳舞》),所以我想我要花几个小时为男孩们准备一些申请。 然后我意识到这是学习WPF的绝佳机会。 我了解WPF背后的一般想法,克里斯·塞尔斯( Chris Sells)向我解释了其中的某些方面。 可以说,WPF是对Windows Client Developer应该如何工作的完整重新构想-因此,对于像我这样深深地融入PeekMessage的人们来说,它是相对不可访问的。 ;)

File|New WPF Application and some poking around got me some progress, but I was really trying to make the code clean. I had two goals: make it work and do it well.

File | New WPF应用程序和一些戳戳为我带来了一些进步,但我实际上是在尝试使代码更简洁。 我有两个目标:使其发挥作用并做好。

Then, it hit me. "Make it work' usually is the most important goal, so I accepted that I don't know WPF and just made it work using techniques I already knew. About 6 hours later, a lot of hacking, some sample wav files of kids laughing, a quick web search for free "Web 2.0 templates," register a domain, upload, and I had http://www.babysmash.com and a workable ClickOnce WPF application that's about 60% of where I want it.

然后,它打击了我。 “使它正常工作通常是最重要的目标,因此我接受我不知道WPF的知识,只是使用我已经知道的技术使其工作。大约6个小时后,大量黑客攻击,一些样本WAV文件让孩子们大笑,可以在网上快速搜索免费的“ Web 2.0模板”,注册一个域,然后上传,并且我拥有http://www.babysmash.com和一个可用的ClickOnce WPF应用程序,该应用程序约占我所需位置的60%。

特征 (Features)

Here's some of the "features." Note that some of these are technical features. Some are kind of obscure, but as a whole, I think these represent a good representative mix of the kinds of things that Windows Client Programmers might find themselves trying to figure out. I think it's a decent sample because it's complex without being oppressively so, it's easy to get one's head around the requirements, it has a lot of possibilities, and it touches all over the platform (BCL, WinForms, Win32, WPF).

这里是一些“功能”。 请注意,其中一些是技术功能。 有些是模糊的,但总的来说,我认为它们代表了Windows客户端程序员可能会发现自己想要解决的各种问题的良好代表。 我认为这是一个不错的示例,因为它复杂而又不会让人感到压抑,因此很容易满足要求,它有很多可能性,并且涉及整个平台(BCL,WinForms,Win32,WPF)。

当前功能 (Current Features)
  • Silly Graphics

    愚蠢的图形
  • Options Dialog and Settings saved in Isolated Storage

    选项对话框和设置保存在独立存储中
  • Keyboard Hooks - Disabled Windows Key, ALT-TAB, Ctrl-Esc

    键盘挂钩-禁用的Windows键,ALT-TAB,Ctrl-Esc
  • ClickOnce (is it viable? sure makes auto-updating easy)

    ClickOnce(可行吗?确保轻松进行自动更新)
  • Kiosk Mode (Full Screen)

    信息亭模式(全屏)
  • Multi-monitor Support (almost)

    多显示器支持(几乎)
  • Multimedia, Playing audio files

    多媒体,播放音频文件
  • Text to Speech

    文字转语音
未来功能的想法(Future Features Ideas)
  • 3D? Animations? Gradients?

    3D? 动画? 渐变?
  • Code Signing Certificate to avoid warning

    代码签名证书以避免警告
  • Mouse drag/painting support  

    鼠标拖动/绘画支持
  • Better/more Multimonitor options

    更好/更多的多显示器选项
    • Simultaneously add shapes on n monitors

      n个监视器上同时添加形状

  • Optional install as Screensaver?

    可选安装为屏幕保护程序吗?
  • When .NET 3.5 is released, support the smaller .NET 3.5 Client Install

    当发布.NET 3.5时,支持较小的.NET 3.5客户端安装
  • Add custom WAV files (my voice?) for letters/shapes, rather than TTS

    为字母/形状而不是TTS添加自定义WAV文件(我的声音?)

    • Maybe let parents record their own voices

      也许让父母记录自己的声音
  • Localized?

    本地化?

    • Does it work on non-English Keyboards/Systems?

      它可以在非英语键盘/系统上工作吗?
    • Does it make sense/is it useful with non-Latin languages? Chinese, Arabic?

      这对非拉丁语言有意义吗? 中文,阿拉伯语?
  • Logging/phone-home when exceptions happen

    发生异常时记录/回拨电话
  • About Box (woohoo!)

    关于Box(woohoo!)

我是否提过代码很烂? (Did I mention the code sucks deeply?)

it also has some "hidden features." By hidden features, I mean, the code sucks. Deeply. Which is kind of the whole point. After I abandoned my "do it well" goal and focused on "make it work," I made ridiculous progress. Of course, I'm not sure the fate of my immortal soul after writing this code, but calling back to last week's post on how none of us really knows what we're doing, why not use this as a learning experience?

它还具有一些“隐藏功能”。 我的意思是隐藏功能,代码很烂。 深。 这很重要。 在我放弃了“做得好”的目标并专注于“使其成功”之后,我取得了可笑的进步。 当然,在编写完这段代码后,我不确定我的不朽灵魂的命运,但是回想上周的帖子,我们没人真正知道我们在做什么,为什么不将此作为学习经验呢?

I decided to not only hack this together, but also to consciously not do a refactoring pass. This is the code exactly and horribly as written the first time, comments, dead code, duplicated blocks, and random copy-pastes from the bathroom wall of code CodeProject and MSDN. Don't judge me too harshly because you KNOW you've written this kind of crap yourself, Dear Reader. The kind of code that makes you need a shower later, but it works and it solved the problem.

我决定不仅要一起破解,而且要有意识地不进行重构。 这是第一次编写的代码,完全是令人恐惧的代码,注释,无效代码,重复的块以及从CodeProject和MSDN 的洗手间墙上 随机粘贴 的代码 。 别太苛刻地判断我,因为亲爱的读者,您知道自己已经写过这种胡扯。 那种使您稍后需要冲凉的代码,但是它可以工作,并且可以解决问题。

我看到的问题 (Problems as I see them)

The code is on CodePlex, and this is my own stream-of-consciousness review of the code and functionality.

该代码位于CodePlex上,这是我对代码和功能的自觉性回顾。

  • No real design

    没有实际设计
  • No separations of concerns between objects

    对象之间没有关注点分离
  • Utils class (isn't there always a Utils class?) is schizophrenic

    实用程序类(不是总是有实用程序类吗?)是精神分裂症
  • Unclear to me how to convert the low level Win32 calls to WPF-eese.

    我不清楚如何将低级Win32调用转换为WPF-eese。
  • I think there's easier way to have "stroked" (outined) characters.

    我认为有一种更轻松的方式来“描边”(过时的)字符。
  • Not modular - no way to add new shapes and have sounds associated with them.

    不是模块化的-无法添加新形状并伴有声音。
  • ConfigurationManager/IsolatedStorage - feels like I shouldn't have had to do that.

    ConfigurationManager / IsolatedStorage-感觉我不需要这样做。
  • Audio - used Win32 APIs. Do the WPF managed API have the same perf?

    音频-使用的Win32 API。 WPF托管API是否具有相同的性能?
  • If you slam on the keyboard too fast, like wipe your hand over it, it can crash in un-managed code. Is this the global keyboard hook gone wrong or something more sinister?

    如果您用太快的速度猛击键盘,例如将手擦拭在键盘上,则它可能会在非托管代码中崩溃。 这是全局键盘挂钩出了问题还是更加险恶?
  • Need to capture Alt-Space

    需要捕获Alt-Space
  • Relationship between Main Window, Options, and configuration details is shaky at best. There should be a pattern for chunks of config state that might change during the process.

    主窗口,选项和配置详细信息之间的关系充其量是不稳定的。 应该有一个模式的配置状态块可能会在此过程中更改。
  • The random letter/shape positioning has some hard-coded fudge factors that feel gross.

    随机字母/形状定位具有一些硬编码的软糖感觉,这些感觉很明显。
  • No tests - how would you test something like this?

    没有测试-您如何测试这样的东西?

  • No thought to threading issues (do I have any?)

    没有想到线程问题(我有吗?)
  • Multimonitor is cheesy, and the Windows on other monitors don't update unless they have focus. How can dispatch (Replay/Tivo?) keystrokes/events too n windows at once so they all update?

    Multimonitor很俗气,其他显示器上的Windows除非有重点,否则不会更新。 如何派遣(重播/ TiVo公司?)按键/事件太N个窗口一下子让他们都更新?

  • Multimonitor - I'd like to detect on window being closed, then close them all.

    Multimonitor-我想检测窗口是否关闭,然后全部关闭。
  • Splash screen?

    启动画面?
  • No tracing, debugging, exception handling, logging.

    没有跟踪,调试,异常处理,日志记录。
  • I keep calling into System.Windows.Forms. Are there known WPF limitations on keyboard handling?

    我一直在调用System.Windows.Forms。 WPF在键盘处理方面是否存在已知限制?
  • If you hit enough keys fast enough, you have to wait for the "queue" to empty. Can I solve that and drop keys if something fills to fast? My own key queue?

    如果您以足够快的速度敲击了足够的按键,则必须等待“队列”清空。 如果速度很快,我可以解决这个问题并放下钥匙吗? 我自己的密钥队列?
  • Not localized - magic strings.

    未本地化-魔术弦。
  • I'm not really using XAML. Is there a better, more declarative way to do some of this?

    我不是真的在使用XAML。 是否有更好的,更具声明性的方法来执行此操作?

本实验 (The Experiment)

I'd like to try two things here. First, what I'd like to do is have a group code review. Leave your thoughts in the CodePlex Issue Tracker and code in <pre> tags. Be sure to read them first so you aren't duplicating effort. Of course, even better, feel free to blog your improvements and diffs or email me diff files (firstname at lastname.com).

我想在这里尝试两件事。 首先,我想做的是对组代码进行审查。 将您的想法留在CodePlex问题跟踪器中,并将代码保留在<pre>标记中。 请务必先阅读它们,以免重复工作。 当然,更好的是,可以随时通过博客将您的改进和差异发布到博客,或通过电子邮件将差异文件(lastname.com上的名字)发送给我。

Second, I'm going to hunt down WPF programmers. Not just Microsoft Employees, although I'll go find the WPF team and ask them, but I want to talk people who have succeeded and failed at WPF applications and get their ideas on refactorings, structure, design, and correctness. Help me (us) understand how it works and if it's better.

其次,我将寻找WPF程序员。 尽管我会去找WPF团队并问他们,不仅是Microsoft员工,而且我想谈一谈在WPF应用程序上成功失败的人,并获得有关重构,结构,设计和正确性的想法。 帮助我(我们)了解其工作原理以及是否更好。

Then (hopefully) over a series of blog posts and maybe a podcast or two, we'll have two applications, before and after, that we can look at. One will be my initial hacked-together-but-functional application, and one will be a completely refactored, group-vetted, expert-reviewed sample that represents (theoretically) a well-written WPF application. The app will implement all the features above and more, and each "feature" will be a little best-practice that someone can use in their app. This way we'll have not just a random sample - with credit to Rob Conery's MVC Storefront application and his transparent design process - but two, before and after, and at some point I'm hoping my brain will break out of my Win32 thinking and I'll better understand WPF idioms.

然后(希望)在一系列博客文章以及一两个播客上,我们将在之前和之后有两个应用程序可供研究。 一个将是我最初被黑客入侵但功能正常的应用程序,一个将是一个完全重构的,经过小组审查,经过专家评审的示例,该示例(理论上)代表一个编写良好的WPF应用程序。 该应用程序将实现以上所有功能,并且每个“功能”都是某人可以在其应用程序中使用的一些最佳实践。 这样,我们不仅会有一个随机样本-归功于Rob Conery的MVC Storefront应用程序和他透明的设计过程-而是两个,之前和之后,在某个时候,我希望我的大脑会摆脱我的Win32思维而且我会更好地了解WPF习惯用法。

I will tag the posts on my blog in the BabySmash category. I'll also be trying some other mostly unrelated experiments, as I'll use Git for local, offline source control, but I'll be pushing my major commits from Git to TFS (Team Foundation Server) at CodePlex as well as using TFS for issue tracking.

我将在Blog上的BabySmash类别中标记这些帖子。 我还将尝试其他一些几乎不相关的实验,因为我将Git用于本地,离线源代码控制,但是我会将主要提交从Git推送到CodePlex的TFS(Team Foundation Server)以及使用TFS用于问题跟踪。

Have at it, the source is up on CodePlex, you can download a ZIP.

有了它,源代码在CodePlex上,您可以下载一个ZIP

翻译自: https://www.hanselman.com/blog/introducing-babysmash-a-wpf-experiment

wpf-mvcdemo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值