Custom control problems(EDIT)<p align=left><font face=Arial size=2></font> </p> <p>I am making a custom control with a label that pops up on double click a textbox wich returns text to the label on double click, enter or lose focus. It also centers itself beneath another control.</p> <p align=left> </p> <p align=left>I got a couple of problems:</p> <p align=left>1. The centering doesn't occur when the custom control tries to extend beyond the above control's left side, it continues to extend to the right instead of centering.</p> <p align=left>2. When the textbox pops up it doesn't receive focus from the Focus() method or keyboard input, instead the user must push the textbox again for it to gain focus and keyboard input.</p> <p align=left> </p> <p align=left>Project download:</p> <p align=left><a title="http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html" href="http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html">http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html</a></p> <p align=left> </p> <p align=left>EDIT: Problem 2 solved with:</p> <p align=left> </p><font color="#0000ff" size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div><font color="#0000ff" size=2> <p align=left>void</font><font size=2> textBox_Loaded(</font><font color="#0000ff" size=2>object</font><font size=2> sender, </font><font color="#2b91af" size=2>RoutedEventArgs</font><font size=2> e)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>textBox.Focus();</p> <p align=left>textBox.Select(0, textBox.Text.Length);</p> <p align=left>e.Handled = </font><font color="#0000ff" size=2>true</font><font size=2>;</p></blockquote> <p align=left>}</p></font> <p align=left> </p></div></div> <p align=left> </p></font> <p></p><font size=2> <p align=left></p>Problem 1 isn't a real issue anymore because it's solved in my main app, however remains a curiosity.</font>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z9dd3101d-9d59-4de2-99a4-608e28cf9cddhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9dd3101d-9d59-4de2-99a4-608e28cf9cdd#9dd3101d-9d59-4de2-99a4-608e28cf9cddhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9dd3101d-9d59-4de2-99a4-608e28cf9cdd#9dd3101d-9d59-4de2-99a4-608e28cf9cddw0lfshad3http://social.msdn.microsoft.com/Profile/en-US/?user=w0lfshad3Custom control problems(EDIT)<p align=left><font face=Arial size=2></font> </p> <p>I am making a custom control with a label that pops up on double click a textbox wich returns text to the label on double click, enter or lose focus. It also centers itself beneath another control.</p> <p align=left> </p> <p align=left>I got a couple of problems:</p> <p align=left>1. The centering doesn't occur when the custom control tries to extend beyond the above control's left side, it continues to extend to the right instead of centering.</p> <p align=left>2. When the textbox pops up it doesn't receive focus from the Focus() method or keyboard input, instead the user must push the textbox again for it to gain focus and keyboard input.</p> <p align=left> </p> <p align=left>Project download:</p> <p align=left><a title="http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html" href="http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html">http://files.filefront.com/WpfApplication13rar/;9222886;/fileinfo.html</a></p> <p align=left> </p> <p align=left>EDIT: Problem 2 solved with:</p> <p align=left> </p><font color="#0000ff" size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div><font color="#0000ff" size=2> <p align=left>void</font><font size=2> textBox_Loaded(</font><font color="#0000ff" size=2>object</font><font size=2> sender, </font><font color="#2b91af" size=2>RoutedEventArgs</font><font size=2> e)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>textBox.Focus();</p> <p align=left>textBox.Select(0, textBox.Text.Length);</p> <p align=left>e.Handled = </font><font color="#0000ff" size=2>true</font><font size=2>;</p></blockquote> <p align=left>}</p></font> <p align=left> </p></div></div> <p align=left> </p></font> <p></p><font size=2> <p align=left></p>Problem 1 isn't a real issue anymore because it's solved in my main app, however remains a curiosity.</font>Sun, 09 Dec 2007 12:14:01 Z2007-12-11T08:20:22Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9dd3101d-9d59-4de2-99a4-608e28cf9cdd#7cc81dae-d413-499b-9acb-822d03af76f6http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9dd3101d-9d59-4de2-99a4-608e28cf9cdd#7cc81dae-d413-499b-9acb-822d03af76f6Wei Zhou - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Wei%20Zhou%20-%20MSFTCustom control problems(EDIT)Hi w0lfshad3 <p align=left> </p> <p align=left>I think that this is because the calculation formula is not right. The following example has similar situation which shows how to center the TextBox control.</p> <p align=left> </p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">namespace</span> ForumProjects</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>{</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>    <span style="color:blue">public</span> <span style="color:blue">partial</span> <span style="color:blue">class</span> <span style="color:#2b91af">MainWindow</span> : <span style="color:#2b91af">Window</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>    {</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>        <span style="color:blue">private</span> <span style="color:blue">void</span> TextBox_TextChanged(<span style="color:blue">object</span> sender, <span style="color:#2b91af">TextChangedEventArgs</span> e)</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>        {</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>            <span style="color:blue">if</span> (!<span style="color:blue">this</span>.TheButton.IsLoaded || !<span style="color:blue">this</span>.TheTextBox.IsLoaded) <span style="color:blue">return</span>;</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left> </p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>            <span style="color:blue">double</span> buttonHoriCenter = <span style="color:blue">this</span>.TheButton.ActualWidth / 2 + <span style="color:#2b91af">Canvas</span>.GetLeft(<span style="color:blue">this</span>.TheButton);</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>            <span style="color:blue">double</span> textBoxWidth = <span style="color:blue">this</span>.TheTextBox.ActualWidth;</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>            <span style="color:blue">double</span> textBoxLeft = buttonHoriCenter - textBoxWidth / 2;</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>            <span style="color:#2b91af">Canvas</span>.SetLeft(<span style="color:blue">this</span>.TheTextBox, textBoxLeft);</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>        }</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>    }</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>}</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">&lt;</span><span style="color:#a31515">Window</span><span style="color:red"> x</span><span style="color:blue">:</span><span style="color:red">Class</span><span style="color:blue">=&quot;ForumProjects.MainWindow&quot;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>       <span style="color:red">xmlns</span><span style="color:blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>       <span style="color:red">xmlns</span><span style="color:blue">:</span><span style="color:red">x</span><span style="color:blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>       <span style="color:red">x</span><span style="color:blue">:</span><span style="color:red">Name</span><span style="color:blue">=&quot;TheWindow&quot;</span><span style="color:red"> Title</span><span style="color:blue">=&quot;MainWindow&quot;</span><span style="color:red"> Height</span><span style="color:blue">=&quot;600&quot;</span><span style="color:red"> Width</span><span style="color:blue">=&quot;800&quot;&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;</span><span style="color:#a31515">Window.Resources</span><span style="color:blue">&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;/</span><span style="color:#a31515">Window.Resources</span><span style="color:blue">&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left> </p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;</span><span style="color:#a31515">Canvas</span><span style="color:red"> Name</span><span style="color:blue">=&quot;RootLayout&quot;</span><span style="color:red"> Background</span><span style="color:blue">=&quot;AliceBlue&quot;&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">        </span><span style="color:blue">&lt;</span><span style="color:#a31515">Button</span><span style="color:red"> Name</span><span style="color:blue">=&quot;TheButton&quot;</span><span style="color:red"> Width</span><span style="color:blue">=&quot;100&quot;</span><span style="color:red"> Height</span><span style="color:blue">=&quot;100&quot;</span><span style="color:red"> Canvas.Left</span><span style="color:blue">=&quot;50&quot;</span><span style="color:red"> Canvas.Top</span><span style="color:blue">=&quot;50&quot;/&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">        </span><span style="color:blue">&lt;</span><span style="color:#a31515">TextBox</span><span style="color:red"> Name</span><span style="color:blue">=&quot;TheTextBox&quot;</span><span style="color:red"> Canvas.Left</span><span style="color:blue">=&quot;80&quot;</span><span style="color:red"> Canvas.Top</span><span style="color:blue">=&quot;150&quot;</span><span style="color:red"> TextChanged</span><span style="color:blue">=&quot;TextBox_TextChanged&quot;&gt;</span><span style="color:#a31515">TTTTTT</span><span style="color:blue">&lt;/</span><span style="color:#a31515">TextBox</span><span style="color:blue">&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:#a31515">    </span><span style="color:blue">&lt;/</span><span style="color:#a31515">Canvas</span><span style="color:blue">&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">&lt;/</span><span style="color:#a31515">Window</span><span style="color:blue">&gt;</span></p> <p align=left> </p></div></div> <p align=left> </p></span> <p></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue"></span></p> <p align=left>Best Regards,</p> <p align=left>Wei Zhou</p>Tue, 11 Dec 2007 05:58:42 Z2007-12-11T08:20:22Z