MY MEMO
[WPF] 기능 모음 본문
Page Load시 실행하는 함수
1 2 3 4 5 6 7 8 | public MainWindow() { InitializeComponent(); this .Loaded += new RoutedEventHandler(Page_Loaded); } private void Page_Loaded(object sender, RoutedEventArgs e) { } |
특정 UI위에서 키보드를 누르면 실행하게 하는 법
+) key down과 up의 차이 : down - 키가 눌리면 실행 / up -키가 눌렸다 떼어지면 실행
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public MainWindow() { InitializeComponent(); Web_List.KeyDown += Web_List_KeyboardDownEvent; } private void Web_List_KeyboardDownEvent(object sender, KeyEventArgs e) { //enter key pressed if (e.Key == Key.Return) { } //control + d if ((Keyboard.Modifiers == ModifierKeys.Control) && (Keyboard.IsKeyDown(Key.D))) { } } |
List 동적으로 생성하기
MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <ListBox x:Name= "" FontFamily= "Pavanam" HorizontalAlignment= "Center" Height= "534" Width= "473" BorderBrush= "#ffffff" Margin= "20,0,25.4,0" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation= "Vertical" > <StackPanel Orientation= "Horizontal" > <Image Source= "" Margin= "10" Width= "25" Height= "25" /> <StackPanel Orientation= "Vertical" > <TextBlock x:Name= "" FontFamily= "Pavanam" FontSize= "15" Text= "{Binding Content}" VerticalAlignment= "Center" Margin= "3" /> </StackPanel> </StackPanel> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> |
MainWindow.xaml.cs
1 2 3 4 5 6 | //listbox clear list.Clear(); //listbox에 동적으로 더하기 list.Add( new ListValue() { Content = content, Url = url }); Web_List.ItemsSource = list; |
Listbox의 맨 첫번째 행으로 Keyboard focus하기
//listbox 이외에는 : Keyboard.Focus(focus할 곳);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | try { listbox.SelectedItem = listbox.Items[0]; listbox.UpdateLayout(); // Pre-generates item containers var listBoxItem = (ListBoxItem)listbox .ItemContainerGenerator .ContainerFromItem(listbox.SelectedItem); listBoxItem.Focus(); Keyboard.Focus(listBoxItem); } catch { MessageBox.Show( "No List Available" ); return ; } |
현재 선택된 list받아오기
1 2 3 4 5 6 | if (list이름.SelectedIndex > -1) { var selected_list = ( class 이름)list이름.SelectedItem; string url = selected_list .Url; } } |
웹을 실행하기
1 | Process.Start( new ProcessStartInfo(url)); |
'STUDYING > C#' 카테고리의 다른 글
[C#] C# 기본 문법 - 2 (0) | 2018.03.22 |
---|---|
[C#] C# 기본 문법 - 1 (0) | 2018.03.22 |
[WPF] Web Scraping (0) | 2017.09.01 |
[WPF] Sqlite 사용하기 (0) | 2017.09.01 |
[WPF] toast notification (0) | 2017.08.31 |