Search This Blog

Friday, November 27, 2009

Team Foundation Server 2008 安装

  1. Team Foundation Server 2008 安装所需的其它组件
    • Windows 2008 + SP2
    • IIS 6.0
    • SQL Server 2005 + SP3 / SQL Server 2008 + SP1
    • Windows PowerShell 1.0
    • SharePoint Server + SP1

Friday, November 13, 2009

在VS2008的WPF工程中添加事件的方法

在VS2008中WinForm或都者ASP.net工程中如果选定一个控件,可能通过双击属性窗口的事件一览表中的相应事件来添加事件及事件函数。可是在WPF的工程中属性窗口中并没有事件一览表。如果添加正确的事件及事件函数呢?

如下图:

image

有如下三种方法:

一,通过双击控件。这种方法只能添加极少数但是最常用的事件。

二,通过XAML编辑器。通过XAML编辑器的代码IntelliSence功能。如下图,在标签内部,输入一个空格,就会显示如下的属性列表。选择相应的事件,事件的前面会有一个小闪电的标志。

image

选定事件之后,按回车确定之后,会出现另外一个IntelliSense显示是否要添加事件函数。再选定就OK了。

image

三,通过代码编辑器。在窗口(或其它窗口级对象,如Page)的构造函数中添加事件。如图所示。

输入控件名,按下点之后,会出现一个列表,在里面找到需要的事件,选定。

image

然后输入一个空格跟着一个加号,再跟着一个等于号,会出现一个IntelliSense提示。

image

按提示输入一个TAB之后,会出现下面的IntelliSense提示。

image 再输入一个TAB就可以创建事件函数了。

Thursday, November 12, 2009

今天(2009年11月13日)的技术新闻

. 微软发布了WM6.5的终端和Windows Marketplace for Mobile。

手机+电视+电脑+云 的概念,真的能实现吗?

. Google公布了一种新的语言Go。现在的语言已经很多了。但是微软基于VB+C#,原Borland基于Pascal和Google基于Python。一般一个公司只重点支持一种语言。Google把Go放在什么位置呢?只是其它一种代替C/C++的语言吗?

Go is …

… simple
package main

import "fmt"

func main() {
fmt.Printf("Hello, 世界\n")
}


… fast


Go compilers produce fast code fast. Typical builds take a fraction of a second yet the resulting programs run nearly as quickly as comparable C or C++ code.



… safe


Go is type safe and memory safe. Go has pointers but no pointer arithmetic. For random access, use slices, which know their limits.



… concurrent


Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines, with strong support from the language. Run thousands of goroutines if you want—and say good-bye to stack overflows.



… fun


Go has fast builds, clean syntax, garbage collection, methods for any type, and run-time reflection. It feels like a dynamic language but has the speed and safety of a static language. It's a joy to use.



… open source

BackgroundWorker的用法

在WPF中,使用BackgroundWorker可以将繁重的工作放到后台。

源代码如下:

XAML:

<Window x:Class="BackgroundWorkerTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Button Margin="78,110,77,114" Name="button1" Click="button1_Click">Do Work</Button>
        <CheckBox Height="16" Margin="81,88,77,0" Name="checkBox1" VerticalAlignment="Top">Do work background</CheckBox>
        <TextBox Height="23" Margin="81,0,77,85" Name="textBox1" VerticalAlignment="Bottom" />
    </Grid>
</Window>

 

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BackgroundWorkerTest
{
    /// <summary>
    /// Window1.xaml の相互作用ロジック
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.textBox1.Text = "";
            if (checkBox1.IsChecked == true)
            {
                System.ComponentModel.BackgroundWorker myWorker = new System.ComponentModel.BackgroundWorker();
                myWorker.DoWork += myWorker_DoWork;
                myWorker.RunWorkerCompleted += myWorker_RunWorkerCompleted;
                myWorker.RunWorkerAsync();
            }
            else {
                heavyJob();
                this.textBox1.Text = "job is done";
            }
        }

        private void heavyJob() {
            Int64 number = 1000000000;
            Int64 temp = 0;
            for (int cnt = 1; cnt < number; cnt++) {
                if ((cnt % 2) == 0)
                {
                    temp /= cnt;
                }
                else {
                    temp *= cnt;
                }
            }

        }

        private void myWorker_DoWork(Object sender, System.ComponentModel.DoWorkEventArgs e) {
            heavyJob();
        }

        private void myWorker_RunWorkerCompleted(Object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) {

            this.textBox1.Text = "job is done";
        }
    }
}

Wednesday, November 11, 2009

一些测试结果

1. Window标签不一定要Grid标签

2. Grid标签里可以放Frame标签

3. Frame的Source里可以放网页,也可以放Page,但是不能放Window。

4. 可成为XAML的根元素的元素有:StackPanel, DockPanel, Canvas, Grid, Page, Window, NavigationWindow, Application

5. XAML的元素

  • 根元素:见4
  • 控件元素(Control Elements)
    1. 简单控件元素(Simple Controls, System.Windows.Controls)。不包含Content, Item及Header属性。
    2. 内容控件元素(Content Controls)
    3. 项目控件元素(Item Controls)
    4. 标题项目控件元素(Head Item Controls)
    5. 标题内容控件元素(Head Content Controls)
  • 框架元素
  • 形状及几何元素
  • 文档元素

Tuesday, November 10, 2009

Extend Glass Frame Into a WPF Application

参考链接:

http://msdn.microsoft.com/en-us/library/ms748975.aspx

环境

  Windows Vista + Visual Studio 2008

步骤

1. 创建一个C# WPF项目ExtendVistaGlassFrame。

2. 修改XAML文件如下 (注意x:Class的值换成自己的类名):

<Window x:Class="ExtendVistaGlassFrame.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Extended Glass in WPF" Height="300" Width="400"
    Loaded="OnLoaded" Background="Transparent">
    <Grid ShowGridLines="True">
        <DockPanel Name="mainDock">
            <!-- The border is used to compute the rendered height with margins.
           topBar contents will be displayed on the extended glass frame.-->
            <Border Name="topBar" DockPanel.Dock="Top" >
                <Grid Name="grid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="100" Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox Grid.Column="0" MinWidth="100" Margin="0,0,10,5">Path</TextBox>
                    <TextBox Grid.Column="1" MinWidth="75" Margin="0,0,0,5">Search</TextBox>
                </Grid>
            </Border>
            <Grid DockPanel.Dock="Top" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="53*" />
                    <RowDefinition Height="180.04*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBox AcceptsReturn="True" Grid.RowSpan="2" />
            </Grid>
        </DockPanel>
    </Grid>
</Window>

3. 刷新XAML的设计视图。 点击窗口生成onLoad方法。全文如下。编辑之外需要在引用中添加System.Drawing.dll。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Interop;

namespace ExtendVistaGlassFrame
{
    /// <summary>
    /// Window1.xaml の相互作用ロジック
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Obtain the window handle for WPF application
                IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get System Dpi
                System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
                float DesktopDpiX = desktop.DpiX;
                float DesktopDpiY = desktop.DpiY;

                // Set Margins
                NonClientRegionAPI.MARGINS margins = new NonClientRegionAPI.MARGINS();

                // Extend glass frame into client area
                // Note that the default desktop Dpi is 96dpi. The  margins are
                // adjusted for the system Dpi.
                margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96));
                margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96));
                margins.cyTopHeight = Convert.ToInt32(((int)topBar.ActualHeight + 5) * (DesktopDpiX / 96));
                margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96));

                int hr = NonClientRegionAPI.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
                //
                if (hr < 0)
                {
                    //DwmExtendFrameIntoClientArea Failed
                }
            }
            // If not Vista, paint background white.
            catch (DllNotFoundException)
            {
                Application.Current.MainWindow.Background = Brushes.White;
            }
        }
    }
}

3. 添加一个空类, 类名为NonClientRegionAPI.cs。文件内容如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ExtendVistaGlassFrame
{
    class NonClientRegionAPI
    {

        [StructLayout(LayoutKind.Sequential)]
        public struct MARGINS
        {
            public int cxLeftWidth;      // width of left border that retains its size
            public int cxRightWidth;     // width of right border that retains its size
            public int cyTopHeight;      // height of top border that retains its size
            public int cyBottomHeight;   // height of bottom border that retains its size
        };

        [DllImport("DwmApi.dll")]
        public static extern int DwmExtendFrameIntoClientArea(
            IntPtr hwnd,
            ref MARGINS pMarInset);
    }
}

4. 执行。搞定。

第一次考试

准备这个或者下个周六去参加第一次考试。

第一次的考试选了70-502,70-505,70-536三门考试

降价信息

日语考试信息

70-502

70-505

70-536

英语考试信息

70-502

70-505

70-536

新版的MCP考试

终于下了决心要考MCP了。

原来也想过去考,回想起来已经是10年前了。时间过得可真快。总是因为种种原因而放弃了。原来在大学里面是没有钱去考,大学毕业后到处奔波没有时间去考,后来是因为认为考了没有用就没有去考。

因为最近的降价活动,工作上忙的事情也告一个小段落了,下一步的工作也与这个相关,上个星期参加了MDF,还加上其它各种原因。所以这次下了很大决心准备去考了。

新电脑也买好了。看的书也准备好了。算一算要在降价活动期间要考完时间还是很紧的。趁着上班的空闲,好好学习一下。