wpf app全局變量傳參方法(代碼片段 )


清空某行綁定的行數據:
1    int RowIndex = datagrid.SelectedIndex;
2  _Table.Rows[RowIndex]["AVERAGE_PRICE"] = DBNull.Value;
View Code
彈出層對象 :(用於彈出二級頁面)
 1  /// 彈出層對象  
 2         public static NavigationWindow window = null;
 3         #region 使用NavigationWindow彈出頁面
 4         private void ShowNavigationWindow(string title, string uri, int width, int height)
 5         {
 6             try
 7             {
 8                 window = new NavigationWindow();//創建窗體對象
 9                 window.Title = title;
10                 window.MaxHeight = height;
11                 window.MaxWidth = width;
12                 window.Width = this.ActualWidth;
13                 window.Height = this.ActualHeight;
14                 window.WindowStyle = WindowStyle.ToolWindow;//設置邊框樣式
15                 window.WindowStartupLocation = WindowStartupLocation.CenterScreen;//設置顯示位置
16                 window.ResizeMode = ResizeMode.NoResize;//設置顯示
17                 window.Source = new Uri(uri, UriKind.Relative);//設置url
18                 window.ShowsNavigationUI = false;
19                 window.ShowInTaskbar = false;
20                 window.ShowDialog();
21                 window.Close();
22             }
23             catch(Exception ex){
24                 
25             }
26           
27         }
View Code
將變量賦值給app中的全局變量
 1  string backgoodsid = ""; string backgoodscode = "";
 2             DataGridRow row = sender as DataGridRow;
 3             var cell = row.Item;
 4             DataRowView item = cell as DataRowView; 
 5             if (item != null)
 6             {
 7                 backgoodsid = item[0].ToString();
 8             }
 9             if (item != null)
10             {
11                 backgoodscode = item[4].ToString();
12             }
13             string Startdate = STARTDATE.Text;
14             string Enddate = ENDDATE.Text;
15             string a = StaffSearchType.Text;
16             (Application.Current as App).BackgoodsCode = backgoodscode;
17             (Application.Current as App).Backgoodsid = backgoodsid;
18             (Application.Current as App).StartDate = Startdate;
19             (Application.Current as App).EndDate = Enddate;
20             (Application.Current as App).window = a;
View Code
在二級頁面獲取數據
 1   #region 獲取數據
 2 
 3             if ((Application.Current as App).BackgoodsCode != "")
 4             {
 5                 backgoodscode = (Application.Current as App).BackgoodsCode;
 6             }
 7             if((Application.Current as App).Backgoodsid != "")
 8             {
 9                 backgoodsid= (Application.Current as App).Backgoodsid;
10             }
11             if ((Application.Current as App).Type != "")
12             {
13                 type = (Application.Current as App).Type;
14             } 
15             if ((Application.Current as App).StartDate != "")
16             {
17                 Startdate = (Application.Current as App).StartDate;
18             }
19             if ((Application.Current as App).EndDate != "")
20             {
21                 Enddate = (Application.Current as App).EndDate;
22             }
23             if ((Application.Current as App).window != "")
24             {
25                 a = (Application.Current as App).window;
26             }
27             #endregion
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM