• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
轶东的程序世界
博客园       新随笔    联系   管理    订阅  订阅

试试Live Writer的代码插件

插入代码VS2010

http://my.oschina.net/nnhy/blog/11369

修正从vs2010复制代码时中文乱码的问题。好消息:VS2010 SP1已经没有这个问题了。

private void Application_UnhandledException(objectsender, ApplicationUnhandledExceptionEventArgse)
        {
           
// 如果应用程序是在调试器外运行的,则使用浏览器的
            // 异常机制报告该异常。在 IE 上,将在状态栏中用一个
            // 黄色警报图标来显示该异常,而 Firefox 则会显示一个脚本错误。
           
if(!System.Diagnostics.Debugger.IsAttached)
            {

               
// 注意: 这使应用程序可以在已引发异常但尚未处理该异常的情况下
                // 继续运行。
                // 对于生产应用程序,此错误处理应替换为向网站报告错误
                // 并停止应用程序。
               
e.Handled= true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate{ ReportErrorToDOM(e); });
            }
        }


插入代码块
private void btnAbout_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("欢迎进入SilverLight世界!");
            mSvClient.HelloWorldAsync();
            Type tp = Type.GetType("System.Nullable`1[System.DateTime]");
            //==================================================================            
            List<ClassHelper.CustPropertyInfo> lstCustPropertyInfo = new List<ClassHelper.CustPropertyInfo>();
            lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.Int32", "xx"));
            lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.String", "sname"));
            lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.Nullable`1[System.DateTime]", "intime"));            
            dataGrid1.ItemsSource = lp;
        }

这里有一个小小的问题:如果不选择“折叠代码”,那么代码块就没有灰色的背景了。解决办法很简单,
把展开视图代码模版改为:
<div class="cnblogs_code"><pre><%hcode%></pre></div><br>
其实就是在最外面那个div里加上css class,这样代码块有灰色的背景和自适应的滚动条。
Insert Code(英文版)
   1:  private void btnAbout_Click(object sender, RoutedEventArgs e)
   2:          {
   3:              //MessageBox.Show("欢迎进入SilverLight世界!");
   4:   
   5:              mSvClient.HelloWorldAsync();
   6:              Type tp = Type.GetType("System.Nullable`1[System.DateTime]");
   7:              //==================================================================            
   8:              List<ClassHelper.CustPropertyInfo> lstCustPropertyInfo = new List<ClassHelper.CustPropertyInfo>();
   9:              lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.Int32", "xx"));
  10:              lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.String", "sname"));
  11:              lstCustPropertyInfo.Add(new ClassHelper.CustPropertyInfo("System.Nullable`1[System.DateTime]", "intime"));
  12:   
  13:              List<object> lp = new List<object>();
  14:              object obx = ClassHelper.CreateInstance(lstCustPropertyInfo);
  15:              ClassHelper.SetPropertyValue(obx, "xx", 789);
  16:              ClassHelper.SetPropertyValue(obx, "sname", "张三");
  17:              ClassHelper.SetPropertyValue(obx, "intime", DateTime.Now);
  18:              lp.Add(obx);
  19:              obx = ClassHelper.CreateInstance(lstCustPropertyInfo);
  20:              ClassHelper.SetPropertyValue(obx, "xx", 987);
  21:              ClassHelper.SetPropertyValue(obx, "sname", "李四");
  22:              ClassHelper.SetPropertyValue(obx, "intime", null);
  23:              lp.Add(obx);
  24:              
  25:              dataGrid1.ItemsSource = lp;
  26:          }
posted @ 2011-08-10 15:56  赵轶东  阅读(304)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3