Windows Phone 7 Custom Message Box

本文介绍了一个用于Windows Phone 7的通知框组件NotificationBox,它提供了自定义按钮、重复显示消息等功能,简化了用户界面的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


UPDATE: Notification box has been updated: Take a look at http://wpassets.codeplex.com, the new home place for NotificationBox and others.

I’ve wrote a custom message box called NotificationBox for the Windows Phone 7. It gives you an option to pick whatever button you like to have inside the message box. Also It provides a cool feature which is ‘Show this message again’ with isolated settings persistency so you won’t have to create this mechanism by yourself each time you want to give an option to the user suppressing a message.

The usage is similar to the regular message box, except for the fact that you can pass commands with custom actions instead of return values – then switch/ifs.

For example:

NotificationBox.Show(
                "Exit",
                "Are you sure?",
                new NotificationBoxCommand("Yes", () => { }),
                new NotificationBoxCommand("No", () => { }));
NotificationBox.Show(
                "Erase",
                "You are about to loose your data!",
                new NotificationBoxCommand("Ok", () => { }),
                new NotificationBoxCommand("Cancel", () => { }));
NotificationBox.Show(
                "Choose",
                "Choose an option.",
                new NotificationBoxCommand("Save", () => { }),
                new NotificationBoxCommand("Load", () => { }));
NotificationBox.Show(
                "Custom",
                "Click on any of the buttons below.",
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Zzz", () => { }));

Yields:

image image image image

Another version of the Show method called ShowAgain, gives an option to suppress a message:

NotificationBox.ShowAgain(
                "Show Again",
                "Uncheck the show again message and this message won't appear again.",
                "Show this message again",
                false,
                suppressed => { },
                GetType().ToString(),                
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Zzz", () => { }));
NotificationBox.ShowAgain(
                "Show Again",
                "Check the show again message so this message will appear again.",
                "Show this message again",
                true,
                suppressed => { },
                GetType().ToString(),                
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Xxx", () => { }),
                new NotificationBoxCommand("Zzz", () => { }));

The first call with false, displays the following message:

image

Now calling the same method again with the same parameters (at least with GetType().ToString()), won’t open the message in case that the user suppressed it by unchecking the check box.

The second snippet (fourth param is true) forces the message to open event if suppressed, but now the same message appears and the checkbox left unchecked. The user have an option to check it again.

I’ll be happy to have inputs, so please – don’t be shy ;)

You can download the source from CodePlex.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值