1
我寫了一個只允許整數值到文本框的事件。現在需要將文本框值更改爲印度貨幣格式(在文本更改事件)
我的附加要求是,我需要改變文本框的整數值印度貨幣格式(我需要在OnTextchanged事件在WPF實現這一點)
private void validateTextInteger(object sender, EventArgs e)
{
NumberFormatInfo nfi = new CultureInfo("en-IN", false).NumberFormat;
nfi = (NumberFormatInfo)nfi.Clone();
nfi.CurrencySymbol = "";
Exception X = new Exception();
TextBox T = (TextBox)sender;
try
{
if (T.Text.Trim() != "-")
{
int x = int.Parse(T.Text);
T.Text = string.Format(nfi, "{0:C0}", x);
return;
}
}
catch (Exception)
{
try
{
int CursorIndex = T.SelectionStart - 1;
T.Text = T.Text.Remove(CursorIndex, 1);
//Align Cursor to same index
T.SelectionStart = CursorIndex;
T.SelectionLength = 0;
}
catch (Exception)
{
}
}
}
只需將'xml:lang =「en-IN」'添加到'UserControl'或'Window'開始標記。 – XAMlMAX
所有這些都可以替換爲' ' –
XAMlMAX
嗨它不工作,我正在編譯時間錯誤 in Text =「{綁定值StringFormat = \ {0:C \}}「 –