This all began as an attempt to have a numeric textbox. That part is irrelevant but it’s why I created the following class. (By the way, using VS 2012 Express, WPF, C# code-behind).
using System;
using System.Windows.Controls;
namespace Herculese
{
public class IntBox : TextBox
{
<!-- irrelevant code here-->
}
}
So far, so good. I build and this becomes a control which I proceed to use in the xaml:
<local:IntBox Name="txtBox_heightft" Width="60" TextChanged="txtBox_Numeric_Changed" />
Then in my code behind where I’m trying to refer to the text in the textbox using “txtBox_heightft.Text”, I’m informed that “The name ‘txtBox_heightft’ does not exist in the current context”. This confuses me to no end because if I change “local:IntBox” to “TextBox” in the xaml, it works fine but then of course it’s a regular textbox and not my modified version. Do I need to add a reference to the class in the codebehind somehow? This is my first attempt at using a class this way, as I’ve never needed functionality that wasn’t provided by default.
The problem is that you are using Name as a dependency property, you need to use x:Name=”txtBox_heightft” as an extension property 🙂