1
我正在開發一個UWP項目,其中我有UI
中的多個文本框,我附加了x:Name
屬性。我已將所有Textboxes
與單個KeyButton_Down()
事件綁定在一起。我想實現設定每個TextBox
作爲Number
的InputScope
財產。每個文本框的XAML都有InputScope="Number"
集。在後面的代碼中,我無法訪問特定Textbox
的InputScope屬性。 這裏是我的代碼在代碼中的單個事件中訪問多個TextBoxes InputScope屬性
private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
TextBox tb = (TextBox)sender;
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);
string textBoxName = tb.Name;
// TextBox text = new TextBox();
//this line is not working for me
// textBoxName.InputScope = scope;
var state = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift);
var newState = (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
if ((!char.IsControl(Convert.ToChar(e.Key)) && !char.IsDigit(Convert.ToChar(e.Key)) && (Convert.ToChar(e.Key) != '.') && !newState))
{
e.Handled = true;
}
}
是否拋出異常? – Laith
@Laith我想從(發件人)使用文本框名稱; tb.Name.Visibility是不是有 – Apoorv
@Apoorv:如果你喜歡訪問某些屬性,您將不再需要的名字。 tb是你的'TextBox'鑄造的特定對象。您可以直接使用這些屬性:'tb.Visibility'。就像我在我的回答中發佈的那樣...... – WPFGermany