internal SelectionChangedHandler(System.Windows.Controls.ListView owner) { Binding = new Binding("SelectedItems"); Binding.Source = owner; owner.SetBinding(ListView.BindableSelectedItemsProperty, Binding); owner.SelectionChanged += new SelectionChangedEventHandler(Owner_SelectionChanged); }
private void AddModuleTab(string name, out Grid grid, ListView inputIO, ListView outputIO) { TabControl moduleTab = new TabControl(); moduleTab.Style = (Style)App.Current.Resources["TabControlStyle"]; CopyFontData(this.tabItem1, moduleTab); TabItem operationTab = new TabItem(); operationTab.Header = "OPERATION"; operationTab.Height = 50; moduleTab.Items.Add(operationTab); TabItem inputIOListTab = new TabItem(); inputIOListTab.Header = "INPUT IO LIST"; moduleTab.Items.Add(inputIOListTab); inputIOListTab.Content = inputIO; TabItem outputIOListTab = new TabItem(); outputIOListTab.Visibility = System.Windows.Visibility.Collapsed; outputIOListTab.Header = "OUTPUT IO LIST"; moduleTab.Items.Add(outputIOListTab); outputIOListTab.Content = outputIO; Binding bd = new Binding("IsEnabledOutputIODirectControl"); bd.Source = this; bd.Mode = BindingMode.OneWay; outputIO.SetBinding(ListView.IsEnabledProperty, bd); Grid operationGrid = CreateOperationGrid(); ScrollViewer sv = new ScrollViewer(); sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; operationTab.Content = sv; sv.Content = operationGrid; CopyFontData(this.tabItem1, operationTab); CopyFontData(this.tabItem1, inputIOListTab); CopyFontData(this.tabItem1, outputIOListTab); TabItem tabItem = new TabItem(); tabItem.Height = 50; tabItem.Header = name; tabItem.Content = moduleTab; CopyFontData(this.tabItem1, tabItem); grid = operationGrid; tabControl1.Items.Add(tabItem); }
Ctrl.Control ConvertElement(VM.Element vm) { var t = vm.GetType(); if (t == typeof(VM.TableView)) { var tv = (VM.TableView)vm; var lv = new Ctrl.ListView { DataContext = tv }; lv.SetBinding(Ctrl.ListView.ItemsSourceProperty, tv.Path); lv.SetBinding(Ctrl.ListView.VisibilityProperty, new Binding("Items.Count") { RelativeSource = RelativeSource.Self, Mode = BindingMode.OneWay, Converter = new IntToVisibilityConverter() }); if (tv.ItemType.IsPrimitive != true) { var gv = new Ctrl.GridView(); var props = tv.ItemType.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var xt in props) { gv.Columns.Add(new Ctrl.GridViewColumn { DisplayMemberBinding = new Binding(xt.Name), Header = xt.Name, Width = Double.NaN, }); } lv.View = gv; } return(lv); } if (t == typeof(VM.SlideInput)) { var slider = new Ctrl.Slider { Name = vm.Name, DataContext = (VM.SlideInput)vm, }; slider.SetBinding(Ctrl.Slider.ValueProperty, vm.Path); return(slider); } if (t == typeof(VM.EnumInput)) { return(new MechaCtrl.EnumInput { Name = vm.Name, ViewModel = (VM.EnumInput)vm }); } if (t == typeof(VM.TextView)) { return(new MechaCtrl.TextView { Name = vm.Name, ViewModel = (VM.TextView)vm, }); } if (t == typeof(VM.CheckBox)) { var chkBox = new Ctrl.CheckBox { Name = vm.Name, DataContext = (VM.CheckBox)vm, }; chkBox.SetBinding(Ctrl.CheckBox.IsCheckedProperty, vm.Path); return(chkBox); } if (t == typeof(VM.DateInput)) { return(new MechaCtrl.DateInput { Name = vm.Name, ViewModel = (VM.DateInput)vm, }); } if (t == typeof(VM.TextInput)) { return(new MechaCtrl.TextInput { Name = vm.Name, ViewModel = (VM.TextInput)vm, }); } if (t == typeof(VM.PathInput)) { return(new MechaCtrl.PathInput { Name = vm.Name, ViewModel = (VM.PathInput)vm, }); } if (t == typeof(VM.PasswordInput)) { return(new MechaCtrl.PasswordInput { Name = vm.Name, ViewModel = (VM.PasswordInput)vm, }); } if (t == typeof(VM.Button)) { var btn = new Ctrl.Button { Name = vm.Name, DataContext = vm, }; var btnVm = (VM.Button)vm; btn.Click += async(o, e) => await TryInvokeButton(btnVm); return(btn); } throw new NotImplementedException(); }
private void LoadTransmission() { System.Uri resourceLocater = new System.Uri("/DataSpaceSync;component/TransmissionWPF.xaml", System.UriKind.Relative); UserControl wpf = Application.LoadComponent(resourceLocater) as UserControl; ListView = wpf.FindName("ListView") as ListView; Binding binding = new Binding(); binding.Source = TransmissionList; ListView.SetBinding(ListView.ItemsSourceProperty, binding); ListView.SelectionChanged += ListView_SelectionChanged; OkButton = wpf.FindName("OkButton") as Button; Content = wpf; }
//this method is called to notify the user that a malware has been identified public void NotifyUser(SqlCeDataReader dataReader) { SystemSounds.Asterisk.Play();//alert the user with sound //the event isn't being raised in the UI thread, and you need to marshal over to the UI thread //before creating the window. This is probably as simple as changing your event handler code //the window wont be displayed if we dont change the event handler code as follows Action action = () => { notifyWindow = new Window(); //create a new window notifyWindow.ShowInTaskbar = false; //disable it in taskbar notifyWindow.Title = "A malware has been identified and killed"; //set its title var uriSource = new Uri("logo.ico", UriKind.Relative); notifyWindow.Icon = new BitmapImage(uriSource); notifyWindow.ResizeMode = System.Windows.ResizeMode.NoResize; //set it not resizable notifyWindow.Width = 370; //set width if the window notifyWindow.Height = 400; //set height of the window notifyWindow.Left = Screen.PrimaryScreen.WorkingArea.Right - notifyWindow.Width; notifyWindow.Top = Screen.PrimaryScreen.WorkingArea.Bottom - notifyWindow.Height; notifyWindow.Topmost = true; //Create a Stack Panel and add it to our window StackPanel stackPanel = new StackPanel(); stackPanel.Background = System.Windows.Media.Brushes.Orange; notifyWindow.Content = stackPanel; //now we should continue adding items to our stack panel one by one //fileDetails StackPanel filePanel = new StackPanel();//create a new file panel filePanel.Background = System.Windows.Media.Brushes.PeachPuff; Expander filePanelExpander = new Expander();//create and expander for it filePanelExpander.Expanded += new RoutedEventHandler(changeExpanderBackgroundColor); filePanelExpander.Collapsed += new RoutedEventHandler(revertExpanderBackgroundColor); filePanelExpander.Content = filePanel;//set the content of the expander to our panel filePanelExpander.BorderThickness = new Thickness(2); filePanelExpander.BorderBrush = System.Windows.Media.Brushes.OrangeRed; //create and add expander label System.Windows.Controls.Label filedetailsLabel = new System.Windows.Controls.Label(); filedetailsLabel.Foreground = System.Windows.Media.Brushes.DarkGreen; filedetailsLabel.Content = "File Details"; filedetailsLabel.FontWeight = FontWeights.UltraBold; //bold face the label filePanelExpander.Header = filedetailsLabel; //set the label as the header of the expander filePanelExpander.IsExpanded = true; //expand the file details by default stackPanel.Children.Add(filePanelExpander); //add the expander to our stack panel System.Windows.Controls.Label filepathlabel = new System.Windows.Controls.Label(); filepathlabel.Foreground = System.Windows.Media.Brushes.DarkGreen; filepathlabel.Content = " File Path: " + dataReader["path"].ToString(); filePanel.Children.Add(filepathlabel); System.Windows.Controls.Label filetypelabel = new System.Windows.Controls.Label(); filetypelabel.Content = " File Type: " + dataReader["file_type"].ToString(); filetypelabel.Foreground = System.Windows.Media.Brushes.DarkGreen; filePanel.Children.Add(filetypelabel); System.Windows.Controls.Label sha1label = new System.Windows.Controls.Label(); sha1label.Foreground = System.Windows.Media.Brushes.DarkGreen; sha1label.Content = " SHA1: " + dataReader["sha1"].ToString(); filePanel.Children.Add(sha1label); System.Windows.Controls.Label md5label = new System.Windows.Controls.Label(); md5label.Content = " MD5: " + dataReader["md5"].ToString(); md5label.Foreground = System.Windows.Media.Brushes.DarkGreen; filePanel.Children.Add(md5label); System.Windows.Controls.Label crc32label = new System.Windows.Controls.Label(); crc32label.Content = " CRC32: " + dataReader["crc32"].ToString(); crc32label.Foreground = System.Windows.Media.Brushes.DarkGreen; filePanel.Children.Add(crc32label); //Signature based detection //get the database data ready in a datatable string sqlQuery = @"select * from static where path='" + dataReader["path"] + "'"; SqlCeCommand cmd = new SqlCeCommand(sqlQuery, connection); SqlCeDataAdapter da = new SqlCeDataAdapter(cmd); DataTable table = new DataTable(); da.Fill(table); DataTable flipTable = FlipDataTable(table); StackPanel sigPanel = new StackPanel(); //create a new file panel Expander sigPanelExpander = new Expander(); //create and expander for it sigPanelExpander.Expanded += new RoutedEventHandler(changeExpanderBackgroundColor); sigPanelExpander.Collapsed += new RoutedEventHandler(revertExpanderBackgroundColor); sigPanelExpander.Content = sigPanel;//set the content of the expander to our panel sigPanelExpander.BorderThickness = new Thickness(0); sigPanelExpander.BorderBrush = System.Windows.Media.Brushes.OrangeRed; //1..Creating the label and adding to the stackPanel System.Windows.Controls.Label staticLabel = new System.Windows.Controls.Label(); staticLabel.Foreground = System.Windows.Media.Brushes.DarkGreen; staticLabel.Content = "Signature Based Analysis Detection Ratio: (" + malwareCount.ToString() + "/46)"; staticLabel.FontWeight = FontWeights.UltraBold; //bold face the label sigPanelExpander.Header = staticLabel; stackPanel.Children.Add(sigPanelExpander); //add the expander to our stack panel //2..creating the data grid System.Windows.Controls.ListView listView = new System.Windows.Controls.ListView(); //create a list view listView.Height = 200; //set the height of the listView GridView gridView = new GridView(); //create a grid view Style style = new Style(); //style for removing headers style.Setters.Add(new Setter(System.Windows.Controls.Control.VisibilityProperty, Visibility.Hidden)); Style foregroundStyle = new Style(); //style for removing headers foregroundStyle.Setters.Add(new Setter(System.Windows.Controls.Control.ForegroundProperty, System.Windows.Media.Brushes.Red)); gridView.AllowsColumnReorder = false; listView.Foreground = System.Windows.Media.Brushes.DarkGreen; listView.Background = System.Windows.Media.Brushes.PeachPuff; ScrollViewer.SetVerticalScrollBarVisibility(listView, ScrollBarVisibility.Visible); ScrollViewer.SetHorizontalScrollBarVisibility(listView, ScrollBarVisibility.Hidden); sigPanel.Children.Add(listView); //add it to our panel //listView.SelectionMode = System.Windows.Controls.SelectionMode.Single; listView.View = gridView; //set the liste view's property to the grid view GridViewColumn column1 = new GridViewColumn(); gridView.Columns.Add(column1); column1.SetValue(GridViewColumn.HeaderContainerStyleProperty, style); column1.Width = 30; DataTemplate template = new DataTemplate(); FrameworkElementFactory factory = new FrameworkElementFactory(typeof(System.Windows.Controls.Image)); factory.SetBinding(System.Windows.Controls.Image.SourceProperty, new System.Windows.Data.Binding("2")); template.VisualTree = factory; column1.CellTemplate = template; GridViewColumn column2 = new GridViewColumn(); gridView.Columns.Add(column2); column2.SetValue(GridViewColumn.HeaderContainerStyleProperty, style); column2.Width = 112; column2.DisplayMemberBinding = new System.Windows.Data.Binding("0"); GridViewColumn column3 = new GridViewColumn(); gridView.Columns.Add(column3); column3.Width = 200; column3.SetValue(GridViewColumn.HeaderContainerStyleProperty, style); column3.DisplayMemberBinding = new System.Windows.Data.Binding("1"); System.Windows.Data.Binding bind = new System.Windows.Data.Binding(); bind.Source = flipTable; listView.DataContext = flipTable; listView.SetBinding(System.Windows.Controls.ListView.ItemsSourceProperty, bind); //Behavioural Analysis StackPanel behavPanel = new StackPanel(); behavPanel.Background = System.Windows.Media.Brushes.PeachPuff; Expander behavPanelExpander = new Expander(); behavPanelExpander.Expanded += new RoutedEventHandler(changeExpanderBackgroundColor); behavPanelExpander.Collapsed += new RoutedEventHandler(revertExpanderBackgroundColor); behavPanelExpander.Content = behavPanel; behavPanelExpander.BorderThickness = new Thickness(0); behavPanelExpander.BorderBrush = System.Windows.Media.Brushes.OrangeRed; stackPanel.Children.Add(behavPanelExpander); System.Windows.Controls.Label behavLabel = new System.Windows.Controls.Label(); behavLabel.Foreground = System.Windows.Media.Brushes.DarkGreen; behavLabel.Content = "Behavioural Analysis"; behavLabel.FontWeight = FontWeights.UltraBold;//bold face the label behavPanelExpander.Header = behavLabel; string[] signatures = System.Text.RegularExpressions.Regex.Split(dataReader["signatures"].ToString(), ","); foreach (string signature in signatures) { if (signature != "") { System.Windows.Controls.Label label = new System.Windows.Controls.Label(); label.Content = " " + signature; label.Foreground = System.Windows.Media.Brushes.DarkGreen; behavPanel.Children.Add(label); } } if (behavPanel.Children.Count == 0)//if there is no behavioural malicious patterns then it is clean { System.Windows.Controls.Label label = new System.Windows.Controls.Label(); label.Foreground = System.Windows.Media.Brushes.DarkGreen; label.Content = " No malicious behaviour observed"; behavPanel.Children.Add(label); } //Heuristic Analysis StackPanel heurPanel = new StackPanel(); heurPanel.Background = System.Windows.Media.Brushes.PeachPuff; Expander heurPanelExpander = new Expander(); heurPanelExpander.Expanded += new RoutedEventHandler(changeExpanderBackgroundColor); heurPanelExpander.Collapsed += new RoutedEventHandler(revertExpanderBackgroundColor); heurPanelExpander.Content = heurPanel; heurPanelExpander.BorderThickness = new Thickness(0); heurPanelExpander.BorderBrush = System.Windows.Media.Brushes.OrangeRed; stackPanel.Children.Add(heurPanelExpander); System.Windows.Controls.Label heurLabel = new System.Windows.Controls.Label(); heurLabel.Foreground = System.Windows.Media.Brushes.DarkGreen; heurLabel.Content = "Heuristic Analysis"; heurLabel.FontWeight = FontWeights.UltraBold;//bold face the label heurPanelExpander.Header = heurLabel; System.Windows.Controls.Label hlabel = new System.Windows.Controls.Label(); hlabel.Foreground = System.Windows.Media.Brushes.DarkGreen; hlabel.Content = " This file is found to be " + dataReader["heuristics"].ToString(); heurPanel.Children.Add(hlabel); //Network Analysis StackPanel networkPanel = new StackPanel(); networkPanel.Background = System.Windows.Media.Brushes.PeachPuff; Expander networkPanelExpander = new Expander(); networkPanelExpander.Expanded += new RoutedEventHandler(changeExpanderBackgroundColor); networkPanelExpander.Collapsed += new RoutedEventHandler(revertExpanderBackgroundColor); networkPanelExpander.Content = networkPanel; networkPanelExpander.BorderThickness = new Thickness(0); networkPanelExpander.BorderBrush = System.Windows.Media.Brushes.OrangeRed; stackPanel.Children.Add(networkPanelExpander); System.Windows.Controls.Label networkLabel = new System.Windows.Controls.Label(); networkLabel.Foreground = System.Windows.Media.Brushes.DarkGreen; networkLabel.Content = "Network Activity"; networkLabel.FontWeight = FontWeights.UltraBold;//bold face the label networkPanelExpander.Header = networkLabel; string[] hosts = System.Text.RegularExpressions.Regex.Split(dataReader["network"].ToString(), ","); foreach (string host in hosts) { if (host != "") { System.Windows.Controls.Label label = new System.Windows.Controls.Label(); label.Content = " " + host; label.Foreground = System.Windows.Media.Brushes.DarkGreen; networkPanel.Children.Add(label); } } if (networkPanel.Children.Count == 0)//if there is no behavioural malicious patterns then it is clean { System.Windows.Controls.Label label = new System.Windows.Controls.Label(); label.Content = " No network activity observed"; label.Foreground = System.Windows.Media.Brushes.DarkGreen; networkPanel.Children.Add(label); } timer.Start(); //start the timer notifyWindow.ShowDialog(); //show the window notifyWindow.Closed += new EventHandler(stopTimer); //when the window is closed then stop the timer }; Dispatcher.BeginInvoke(action); }
void Owner_SelectionChanged(object sender, SelectionChangedEventArgs e) { System.Windows.Controls.ListView Owner = (System.Windows.Controls.ListView)sender; BindingOperations.ClearBinding(Owner, ListView.BindableSelectedItemsProperty); Owner.SetBinding(ListView.BindableSelectedItemsProperty, Binding); }