我正在編寫一個函數,它將採用Control Ctrl
作爲Arguement
並修改它的Control.Content
。 是否有任何方法獲取並設置Content
任何Control
??如何獲取WPF中任何控件的「內容」?
代碼:
void RemoveHotKey(Control Ctrl, int KeyIndex)
{
if (Ctrl.Content.ToString().Substring(KeyIndex, 1) == "_") // System.Windows.Controls.Control does not contain a definition for 'Content'
{
Ctrl.Content = Ctrl.Content.ToString().Remove(KeyIndex, 1); // System.Windows.Controls.Control does not contain a definition for 'Content'
}
}
你爲什麼要使用控制類的說法,而不是ContentControl中類參數? – mtijn