MethodBase method = stackTrace.GetFrame(1).GetMethod(); string methodName = method.Name; string className = method.ReflectedType.Name; Console.WriteLine(className + "." + methodName);
How to find FULL name of calling method C#
MethodBase method = stackTrace.GetFrame(1).GetMethod(); string methodName = method.Name; string className = method.ReflectedType.Name; Console.WriteLine(className + "." + methodName);
DelayStartTimeTextBox.PreviewTextInput += StaticResourceModel.PreviewTextInput;
public static class StaticResourceModel { public static void PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = new System.Text.RegularExpressions.Regex("[^0-9]+").IsMatch(e.Text); } }
public ObservableCollectionMyString = new ObservableCollection (new List ());
public ICommand ResetProgramCommand { get { if (_resetProgramCommand == null) { _resetProgramCommand = new RelayCommand(obj => {_event.ResetProgramEvent() , _event.UpdateProgramEvent()}, null); } return _resetProgramCommand; } }
string value = string.empty; string result = "Success"; public ICommand ResetProgramCommand { get { if (_resetProgramCommand == null) { _resetProgramCommand = new RelayCommand(obj => {_event.ResetProgramEvent(),value = result;}, null); } return _resetProgramCommand; } }
首先宣告XDocument的物件,並給它檔案路徑去讀取,然後再new一個ObservableCollection的string泛型,透過linq的語法去取得attribute的參數,並轉成list在轉型放入到ObservableCollection。
XDocument allLanguage = XDocument.Load($@"{Properties.Settings.Default.ConfigPath}"); name = = new ObservableCollection((from data in allLanguage.Descendants("TaskManager").Descendants("Language") select data).Elements("LanguageInfo").Select(args => args.Attribute("name").Value).ToList()); value = new ObservableCollection ((from data in allLanguage.Descendants("TaskManager").Descendants("Language") select data).Elements("LanguageInfo").Select(args => args.Attribute("value").Value).ToList());
如果是要放到一個類別裡面也可以這樣宣告 foreach(XElement element in (from data in allLanguage.Descendants("TaskManager").Descendants("Language") select data).Elements("LanguageInfo")) { StaticResourceModel.ComboBoxValue.Add(new ComboBoxValue() {Name= element.Attribute("name").Value , Value = element.Attribute("value").Value}); }