专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »外文资料 » controlhost:Host a WPF control in a windows application »正文

controlhost:Host a WPF control in a windows application

来源: 发布时间:星期日, 2008年10月5日 浏览:3次 评论:0

In this walkthrough, I will demonstrate how to host a WPF control in a windows application. I invite you to follow this walkthrough:

Walkthrough:

  1. Open VS 2008 or Sharp Develop 3.0, then add a new project, a WPF user control project, if you didn't see it in the projects list view, make sure that the Framework 3.5 is selected. At the top right you can find a combo box that invites you to select witch framework do you want.

  2. Name it WPFControlForWin and then create the project.

  3. After that, copy this xaml code and paste it in the XAML editor

    <UserControl x:Class="WpfForExcel.UserControl1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Height="793" Width="470" Loaded="UserControl_Loaded" ToolTip="Mouse in now"

    MouseEnter="UserControl_MouseEnter" MouseLeave="UserControl_MouseLeave"

    >

    <!--This is XAML code performed by Bejaoui Bechir-->

    <Grid Name="myGrid" Height="765" Width="436">

    <Image Margin="0,17,15,0" Name="Image1" HorizontalAlignment="Right" VerticalAlignment="Top" />

    <Label Margin="8,10,120,11" Name="label1">

    </Label>

    <Label Height="23" HorizontalAlignment="Right" Margin="0,251,28,0" Name="label2" VerticalAlignment="Top" Width="80" FontWeight="Bold">WPF control</Label>

    </Grid>

    </UserControl>

  4. Right click the control and click view code, the code editor will appear, and then implement the code as follow:

    namespace WpfForExcel

    {

    /// <summary>

    /// Interaction logic for UserControl1.xaml

    /// </summary>

    public partial class UserControl1 : UserControl

    {

    public UserControl1()

    {

    InitializeComponent();

    }

    StringBuilder oBuilder1;

    StringBuilder oBuilder2;

    string YougerthenHistory;

    string DihyaHistory;

    System.IO.StringWriter oWriter;

    BitmapImage oBitmap;

    private void UserControl_Loaded(object sender, RoutedEventArgs e)

    {

    //Inititalize the oWriter,oBuilder1,oBuilder2

    oWriter = new System.IO.StringWriter();

    oBuilder1 = new StringBuilder();

    oBuilder2 = new StringBuilder();

    }

    /// <summary>

    /// Void: This method fill the builder

    /// </summary>

    private void FillYougerthenHistory()

    {

    if (YougerthenHistory == "")

    {

    oBuilder1.AppendLine("Yougerthen, king of Numidia (113- 104 BCE).");

    oBuilder1.AppendLine("Yougerthen was the grandson of King Massinissen,");

    oBuilder1.AppendLine("after the death of King Micipsa in 118,");

    oBuilder1.AppendLine("Numidia needed a new king.");

    oBuilder1.AppendLine("Yougerthen used all his skills be the king");

    oBuilder1.AppendLine("Meanwhile,responsibles in Rome was against that");

    oBuilder1.AppendLine("Yougethen, who had bribed the Roman aristocracy");

    oBuilder1.AppendLine("with loads of gold, went to Rome in full ");

    oBuilder1.AppendLine("assurance that nothing would harm him. In ");

    oBuilder1.AppendLine("front of the Senate, it was declared that he ");

    oBuilder1.AppendLine("did not have to explain himself, and he could");

    oBuilder1.AppendLine("return to Numidia.");

    oBuilder1.AppendLine("He said Rome is a coutry for sale for anyone");

    oBuilder1.AppendLine("pays the best prize. ");

    oBuilder1.AppendLine("Finally, in 111, Rome decided to make");

    oBuilder1.AppendLine("a war towards him to defend their position.");

    oBuilder1.AppendLine("It soon escalated to war against Rome. Little ");

    oBuilder1.AppendLine("was achieved by expose his weakness, and he ");

    oBuilder1.AppendLine("used the desert and mountains to hide in or move through so ");

    oBuilder1.AppendLine("that he always could get around the Roman troops.");

    oBuilder1.AppendLine("Six legions are completly neutralized and destroyed");

    oBuilder1.AppendLine("After years of humiliation, the Roman");

    oBuilder1.AppendLine("commander Metellus was replaced by Marius. ");

    oBuilder1.AppendLine("After _disibledevent="Verdana, Arial, Helvetica, sans-serif">Good Dotneting!!!

相关文章

读者评论

  • 共0条 分0页

发表评论

  • 昵称:
  • 内容: