Click here to Skip to main content
13,050,358 members (139,004 online)
Click here to Skip to main content

Stats

529.1K views
23.8K downloads
118 bookmarked
Posted 24 Jan 2009

How to Create a WPF User Control & Use It in a WPF Application ( C# )

, 24 Jan 2009
Creating a WPF User Control & using it in a WPF application ( C# )
CustomToolTip
bin
Release
CustomToolTip.dll
CustomToolTip.pdb
obj
Debug
CustomToolTip.csproj.GenerateResource.Cache
CustomToolTip.dll
CustomToolTip.g.resources
CustomToolTip.pdb
CustomToolTip.Properties.Resources.resources
CustomToolTip_MarkupCompile.cache
TempPE
UserControl1.baml
Release
CustomToolTip.csproj.GenerateResource.Cache
CustomToolTip.dll
CustomToolTip.g.resources
CustomToolTip.pdb
CustomToolTip.Properties.Resources.resources
CustomToolTip_MarkupCompile.cache
TempPE
Properties.Resources.Designer.cs.dll
UserControl1.baml
Properties
CustomToolTip.suo
CustomToolTip.sln.cache
CustomToolTip.dll
WpfApplication1.exe
WpfApplication1.suo
WpfApplication1.sln.cache
WpfApplication1
bin
Release
CustomToolTip.dll
CustomToolTip.pdb
WpfApplication1.exe
WpfApplication1.pdb
WpfApplication1.vshost.exe
WpfApplication1.vshost.exe.manifest
Properties
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.Runtime.InteropServices;
using CustomToolTip;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void rectangle_MouseLeave(object sender, MouseEventArgs e)
        {
            state = true;
            customToolTip.Visibility = Visibility.Hidden;
        }

        bool state = true;
        Random rand = new Random(DateTime.Now.Millisecond);

        private void rectangle_MouseMove(object sender, MouseEventArgs e)
        {
            if (state)
            {
                customToolTip.Visibility = Visibility.Visible;
                customToolTip.UserControlToolTipTitle = (sender as Rectangle).Name.ToUpperInvariant();
                customToolTip.UserControlTextBlockToolTip = "";
                for (int i = 0; i < rand.Next(1, 30); i++)
                    customToolTip.UserControlTextBlockToolTip += (sender as Rectangle).Name + "\t" + i.ToString() + "\n";
            }
            customToolTip.UserControlToolTipX = Mouse.GetPosition(this).X + 10;
            customToolTip.UserControlToolTipY = Mouse.GetPosition(this).Y + 10;
            state = false;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mohammad Dayyan
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 24 Jan 2009
Article Copyright 2009 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid