設置啟動頁
默認最后一個窗口關閉,程序退出,可以設置
修改窗體的icon圖標
修改項目exe圖標
雙擊項目名會看到代碼
其他
在A窗體點擊按鈕打開B窗體,在B窗體設置WindowStartupLocation=“CenterOwner”
在A窗體的代碼設置 B.Owner = this; B.Show(); B窗體生成在A窗體中間
Dispatcher
內容控件
ContentControl
兩個重要屬性
DataTemplate ContentTemplate
Object Content
ToggleButton基類
CheckBox、RadioButton的基類,單擊事件觸發后,isChecked會True、False轉換
IsThreeState="True",三態:True、False、null
CheckBox
CheckBox
點擊事件
ListBox
選中項改變事件
private void mylist_Click(object sender, RoutedEventArgs e)
{if(e.OriginalSource is CheckBox cb){mylist.SelectedItem = cb;txt.Text = $"{mylist.SelectedIndex} {cb.Content} {cb.IsChecked}";}
}
RadioButton
按照GroupName分組,優先級最高,否則按照包含層次分組
private void Button_Click_1(object sender, RoutedEventArgs e){string s = "";foreach (var item in spCountry.Children){if(item is RadioButton rd && rd.IsChecked == true){s += rd.Content + "\r\n";}}foreach (var item in spSex.Children){if (item is RadioButton rd && rd.IsChecked == true){s += rd.Content + "\r\n";}}MessageBox.Show(s);}
RepeatButton
Delay 屬性:表示延時重復執行的毫秒數,就是說,RepeatButton被按下后會立即執行一次回調函數,如果您不松開鼠標,在等待Delay 毫秒后,就開始進行重復執行階段。
Interval 屬性:表示重復執行回調函數的時間間隔毫秒數
TextBox
繼承TextBoxBase
TextBoxBase基類提供了兩個事件
TextChanged:內容被修改
SelectionChanged:選中的文本框內容發生改變
Popup
類似ToolTip(Object類型)鼠標懸停顯示內容
PlacementTarget:獲取或設置Popup控件在哪個控件身邊打開
StaysOpen:默認值為true,表示Popup打開后,如果失去焦點,Popup是否繼續顯示
Img
屬性?