I have a textbox
<TextBox Height="23" Grid.Column="1" PreviewTextInput="AddressBox_PreviewTextInput" HorizontalAlignment="Right" Margin="0,27,13,0" Name="AddressI2C" Text="{Binding Path=AddressMessage, Mode=TwoWay}" VerticalAlignment="Top" Width="128" />
private string _AddressMessage = string.Empty;
public string AddressMessage
{
get
{
return _AddressMessage;
}
set
{
_AddressMessage = value;
NotifyPropertyChanged("AddressMessage");
}
}
Now In my view Model class I have a method which requires me to get the text stored in this textbox and save it in a int variable. Now here is the trick, I have to save only the hexadecimal values inside this variable.
Demonstration:
Textbox value: 0x18
So I should first of all take the text inside the textbox and store only the hexadecimal value inside the variable int. Basically store only 18 inside the integer variable.
I had done this in my C++ aplication as follows:
int address = m_texteditAddress->getText().getHexValue32();
I tried doing the following:
string strValue = AddressMessage;
if(strValue.StartsWith("0x"))
{
strValue = strValue.Remove(0,2);
int address = Convert.ToInt32(strValue);
}
but AddressMessage is always empty even though I am entering "0x23" when I debug the code. The control doesnt enter the loop. Now how can I achieve this????