<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dot Net Thoughts &#187; WPF</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 01 Sep 2010 09:53:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Customize SpellCheck in WPF textbox</title>
		<link>http://www.dotnetthoughts.net/2010/06/22/customize-spellcheck-in-wpf-textbox/</link>
		<comments>http://www.dotnetthoughts.net/2010/06/22/customize-spellcheck-in-wpf-textbox/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 08:43:24 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[SpellCheck]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=936</guid>
		<description><![CDATA[While working on a personal project (fleetIt). I worked on Textbox spell check option. I enabled it, it was working fine, until I added a context menu to to the textbox, for custom commands of my application. It was displaying the spelling errors but the suggestions and correction options was not available. Then I tried [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a personal project (fleetIt). I worked on Textbox spell check option. I enabled it, it was working fine, until I added a context menu to to the textbox, for custom commands of my application. It was displaying the spelling errors but the suggestions and correction options was not available. Then I tried to customize the context menu such a way that it can display both my custom options as well as the system default spell check options. Here is a simple implementation, which helps to customize the context menu and display the spell check suggestions options.</p>
<pre class="brush: xml;">
&lt;Window x:Class=&quot;dotnetthoughts.net.MainWindow&quot;
xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:sys=&quot;clr-namespace:System;assembly=System&quot;
Title=&quot;WPF SpellCheck Demo&quot; Height=&quot;350&quot; Width=&quot;525&quot; Loaded=&quot;Window_Loaded&quot;&gt;
&lt;DockPanel&gt;
&lt;TextBox Name=&quot;txtEdit&quot; SpellCheck.IsEnabled=&quot;True&quot;
                AcceptsReturn=&quot;True&quot;
ContextMenuOpening=&quot;txtEdit_ContextMenuOpening&quot;
                VerticalScrollBarVisibility=&quot;Visible&quot;&gt;
&lt;TextBox.ContextMenu&gt;
&lt;ContextMenu Name=&quot;ctxMenu&quot; /&gt;
&lt;/TextBox.ContextMenu&gt;
&lt;/TextBox&gt;
&lt;/DockPanel&gt;
&lt;/Window&gt;
</pre>
<p>And here is the code behind</p>
<pre class="brush: csharp;">
namespace dotnetthoughts.net
{
    using System;
    using System.IO;
using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;

public partial class MainWindow : Window
    {
public MainWindow()
        {
InitializeComponent();
        }

private void txtEdit_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            int index = 0;
this.txtEdit.ContextMenu.Items.Clear(); //Clearing the existing items
            //Getting the spellcheck suggestions.
SpellingError spellingError = this.txtEdit.GetSpellingError(this.txtEdit.CaretIndex);
if (spellingError != null &amp;&amp; spellingError.Suggestions.Count() &gt;= 1)
            {
                //Creating the suggestions menu items.
foreach (string suggestion in spellingError.Suggestions)
                {
MenuItem menuItem = new MenuItem();
                    menuItem.Header = suggestion;
menuItem.FontWeight = FontWeights.Bold;
menuItem.Command = EditingCommands.CorrectSpellingError;
                    menuItem.CommandParameter = suggestion;
menuItem.CommandTarget = this.txtEdit;
this.txtEdit.ContextMenu.Items.Insert(index, menuItem);
                    index++;
                }
Separator seperator = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator);
                index++;
//Adding the IgnoreAll menu item
MenuItem IgnoreAllMenuItem = new MenuItem();
                IgnoreAllMenuItem.Header = &quot;Ignore All&quot;;
IgnoreAllMenuItem.Command = EditingCommands.IgnoreSpellingError;
IgnoreAllMenuItem.CommandTarget = this.txtEdit;
                this.txtEdit.ContextMenu.Items.Insert(index, IgnoreAllMenuItem);
                index++;
            }
            else
            {
//No Suggestions found, add a disabled NoSuggestions menuitem.
                MenuItem menuItem = new MenuItem();
menuItem.Header = &quot;No Suggestions&quot;;
                menuItem.IsEnabled = false;
this.txtEdit.ContextMenu.Items.Insert(index, menuItem);
                index++;
            }
//.Net 4.0 Supports CustomDictionaries, Option for Adding to dictionary.
int selectionStart = this.txtEdit.GetSpellingErrorStart(this.txtEdit.CaretIndex);
            if (selectionStart &gt;= 0)
            {
                Separator seperator1 = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator1);
                index++;
MenuItem AddToDictionary = new MenuItem();
                AddToDictionary.Header = &quot;Add to Dictionary&quot;;
                //Getting the word to add
this.txtEdit.SelectionStart = selectionStart;
this.txtEdit.SelectionLength = this.txtEdit.GetSpellingErrorLength(this.txtEdit.CaretIndex);
                //Ignoring the added word.
AddToDictionary.Command = EditingCommands.IgnoreSpellingError;
AddToDictionary.CommandTarget = this.txtEdit;
AddToDictionary.Click += (object o, RoutedEventArgs rea) =&gt;
                {
this.AddToDictionary(this.txtEdit.SelectedText);
                };
this.txtEdit.ContextMenu.Items.Insert(index, AddToDictionary);
                index++;
            }

//Common Edit MenuItems.
            Separator seperator2 = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator2);
            index++;
            //Cut
MenuItem cutMenuItem = new MenuItem();
cutMenuItem.Command = ApplicationCommands.Cut;
this.txtEdit.ContextMenu.Items.Insert(index, cutMenuItem);
            index++;
            //Copy
MenuItem copyMenuItem = new MenuItem();
copyMenuItem.Command = ApplicationCommands.Copy;
this.txtEdit.ContextMenu.Items.Insert(index, copyMenuItem);
            index++;
            //Paste
MenuItem pasteMenuItem = new MenuItem();
pasteMenuItem.Command = ApplicationCommands.Paste;
this.txtEdit.ContextMenu.Items.Insert(index, pasteMenuItem);
            index++;
            Separator seperator3 = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator3);
            index++;
            //Delete
MenuItem deleteMenuItem = new MenuItem();
deleteMenuItem.Command = ApplicationCommands.Delete;
            this.txtEdit.ContextMenu.Items.Insert(index, deleteMenuItem);
            index++;
            Separator seperator4 = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator4);
            index++;
            //Select All
MenuItem selectAllMenuItem = new MenuItem();
selectAllMenuItem.Command = ApplicationCommands.SelectAll;
            this.txtEdit.ContextMenu.Items.Insert(index, selectAllMenuItem);
            index++;
        }
        //Method to Add text to Dictionary
private void AddToDictionary(string entry)
        {
using (StreamWriter streamWriter = new StreamWriter(@&quot;D:\WPF\MyCustomDictionary.lex&quot;, true))
            {
streamWriter.WriteLine(entry);
            }
        }

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
//Assigning custom Dictionary to TextBox
this.txtEdit.SpellCheck.CustomDictionaries.Add(new Uri(@&quot;D:\WPF\MyCustomDictionary.lex&quot;));
        }
    }
}
</pre>
<p>The .Net Framework 4.0 supports CustomDictionaries, which helps to create your own Dictionary.</p>
<pre class="brush: csharp;">
//.Net 4.0 Supports CustomDictionaries, Option for Adding to dictionary.
int selectionStart = this.txtEdit.GetSpellingErrorStart(this.txtEdit.CaretIndex);
if (selectionStart &gt;= 0)
{
    Separator seperator1 = new Separator();
this.txtEdit.ContextMenu.Items.Insert(index, seperator1);
    index++;
MenuItem AddToDictionary = new MenuItem();
    AddToDictionary.Header = &quot;Add to Dictionary&quot;;
    //Getting the word to add
this.txtEdit.SelectionStart = selectionStart;
this.txtEdit.SelectionLength = this.txtEdit.GetSpellingErrorLength(this.txtEdit.CaretIndex);
    //Ignoring the added word.
AddToDictionary.Command = EditingCommands.IgnoreSpellingError;
AddToDictionary.CommandTarget = this.txtEdit;
AddToDictionary.Click += (object o, RoutedEventArgs rea) =&gt;
    {
this.AddToDictionary(this.txtEdit.SelectedText);
    };
this.txtEdit.ContextMenu.Items.Insert(index, AddToDictionary);
    index++;
}
</pre>
<p>Here is the screenshot of Demo Application.</p>
<div id="attachment_938" class="wp-caption aligncenter" style="width: 502px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/SpellCheck.png"><img class="size-full wp-image-938" title="WPF Spell Check Demo - Screenshot" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/SpellCheck.png" alt="WPF Spell Check Demo - Screenshot" width="492" height="287" /></a><p class="wp-caption-text">WPF Spell Check Demo - Screenshot</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/06/22/customize-spellcheck-in-wpf-textbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF interoperability with Windows Forms</title>
		<link>http://www.dotnetthoughts.net/2009/11/02/wpf-interoperability-with-windows-forms/</link>
		<comments>http://www.dotnetthoughts.net/2009/11/02/wpf-interoperability-with-windows-forms/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 16:33:51 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=604</guid>
		<description><![CDATA[In October 24th 2009, I got a chance to attend MS Community Techdays at Trivandrum. One of the session was WPF interoperability with Windows Forms. By using this we can use WPF controls in Classic Windows based applications. For this you require a special control called &#8220;ElementHost&#8220;, if you developed any Windows based application in [...]]]></description>
			<content:encoded><![CDATA[<p>In October 24th 2009, I got a chance to attend MS Community Techdays at Trivandrum. One of the session was WPF interoperability with Windows Forms. By using this we can use WPF controls in Classic Windows based applications. For this you require a special control called &#8220;<strong>ElementHost</strong>&#8220;, if you developed any Windows based application in VS 2008, this control will be available under WPF interoperability tab. If you add this control to a Windows Form, Visual Studio will automatically updates the References list. It will add few more references like PresentationCore, PresentationFrameWork, UIAutomationProvider, WindowsBase, WindowsFormsIntegration. Then you can add a WPF User Control to a Windows Form.</p>
<ol>
<li> Create a Windows Application Project.</li>
<li>Right Click on the Project Node in the solution explorer, select Add New Item, and Select User Control(WPF) from Add New Item Dialog.</li>
<li>In the User Contol I wrote some code to change the Color on MouseMove and I wrote the click event in the Codebehind.</li>
<p>XAML Code</p>
<pre class="brush: xml;">
&lt;Grid&gt;
    &lt;Grid.Resources&gt;
        &lt;Style TargetType=&quot;Button&quot; x:Key=&quot;CustomButton&quot;&gt;
            &lt;Setter Property=&quot;FontSize&quot; Value=&quot;15&quot; /&gt;
            &lt;Style.Triggers&gt;
                &lt;Trigger Property=&quot;IsMouseOver&quot; Value=&quot;True&quot;&gt;
                    &lt;Setter Property=&quot;FontSize&quot; Value=&quot;20&quot; /&gt;
                &lt;/Trigger&gt;
            &lt;/Style.Triggers&gt;
        &lt;/Style&gt;
    &lt;/Grid.Resources&gt;
    &lt;Button Style=&quot;{StaticResource CustomButton}&quot;
            Content=&quot;Hello World&quot;
            Click=&quot;Button_Click&quot;&gt;
    &lt;/Button&gt;
&lt;/Grid&gt;
</pre>
<p>Code behind – C#</p>
<pre class="brush: csharp;">
private void Button_Click(object sender, RoutedEventArgs e)
{
	MessageBox.Show(&quot;WPF UserControl Event&quot;);
}
</pre>
<li>Build the Project.</li>
<li>Drag and Drop, ElementHost control from WPF interoperability tab.</li>
<li>You can Set the host the WPF usercontrol either by selecting Select Host Content from Smart Menu, or by Setting the Child Property in the Property List. (The control will be populated in the List only if you build the application, after you added the control.)</li>
<li>You can also do it in runtime by setting Child Property of the Element Host control.</li>
<pre class="brush: csharp;">
private void Form1_Load(object sender, EventArgs e)
{
        SampleWPFCtrl ctrl1 = new SampleWPFCtrl();
            this.elementHost1.Child = ctrl1;
}
</pre>
<div id="attachment_610" class="wp-caption alignnone" style="width: 311px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/11/wpf_screenshot.png" alt="WPF Usercontol Control in Windows Form" title="WPF Usercontol Control in Windows Form" width="301" height="301" class="size-full wp-image-610" /><p class="wp-caption-text">WPF Usercontol Control in Windows Form</p></div>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/11/02/wpf-interoperability-with-windows-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
