/// <summary> /// Creates a CheckBox for switch parameters /// </summary> /// <param name="parameterViewModel">DataContext object</param> /// <param name="rowNumber">Row number</param> /// <returns>a CheckBox for switch parameters</returns> private static CheckBox CreateCheckBox(ParameterViewModel parameterViewModel, int rowNumber) { CheckBox checkBox = new CheckBox(); checkBox.SetBinding(Label.ContentProperty, new Binding("NameCheckLabel")); checkBox.DataContext = parameterViewModel; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; checkBox.SetValue(Grid.ColumnProperty, 0); checkBox.SetValue(Grid.ColumnSpanProperty, 2); checkBox.SetValue(Grid.RowProperty, rowNumber); checkBox.IsThreeState = false; checkBox.Margin = new Thickness(8, rowNumber == 0 ? 7 : 5, 0, 5); checkBox.SetBinding(CheckBox.ToolTipProperty, new Binding("ToolTip")); Binding valueBinding = new Binding("Value"); checkBox.SetBinding(CheckBox.IsCheckedProperty, valueBinding); //// Add AutomationProperties.AutomationId for Ui Automation test. checkBox.SetValue( System.Windows.Automation.AutomationProperties.AutomationIdProperty, string.Format(CultureInfo.CurrentCulture, "chk{0}", parameterViewModel.Name)); checkBox.SetValue( System.Windows.Automation.AutomationProperties.NameProperty, parameterViewModel.Name); return checkBox; }
private static CheckBox GenerateCheckBox(ref Thickness margin, int row, bool value) { CheckBox elevalue = new CheckBox(); elevalue.IsChecked = value; elevalue.SetValue(Grid.RowProperty, row); elevalue.SetValue(Grid.ColumnProperty, 1); elevalue.Margin = margin; return elevalue; }
public static CheckBox PlaceCheckBoxPrimitive(Grid Container, int Col, int Row) { CheckBox checkbox = new CheckBox(); checkbox.SetValue(Grid.ColumnProperty, Col); checkbox.SetValue(Grid.RowProperty, Row); checkbox.Style = (Style)Application.Current.Resources["CellCheckBox"]; Container.Children.Add(checkbox); return checkbox; }
public override void AddUI(Grid grid) { if (Config != null && Config.ShownAtRunTime) { CheckBox chb = new CheckBox() { IsChecked = value == null ? new bool?() : value.Value, Margin = new Thickness(2) }; chb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); chb.SetValue(Grid.ColumnProperty, 1); chb.SetValue(ToolTipService.ToolTipProperty, Config.ToolTip); grid.Children.Add(chb); chb.Checked += (s, e) => { value.Value = true; RaiseCanExecuteChanged(); }; chb.Unchecked += (s, e) => { value.Value = false; RaiseCanExecuteChanged(); }; } }
static void OnFlagTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { Type flagType = args.NewValue as Type; Fx.Assert(flagType == null || flagType.IsEnum, "FlagType should be null or enum"); Fx.Assert(flagType == null || Attribute.IsDefined(flagType, typeof(FlagsAttribute)), "FlagType should be null or have flags attribute"); if (flagType == null) { return; } int index = 0; FlagPanel panel = sender as FlagPanel; string[] flagNames = flagType.GetEnumNames(); string zeroValueString = Enum.ToObject(flagType, 0).ToString(); foreach (string flagName in flagNames) { if (zeroValueString.Equals("0") || !flagName.Equals(zeroValueString)) { CheckBox checkBox = new CheckBox(); panel.Children.Add(checkBox); checkBox.Content = flagName; checkBox.DataContext = panel; checkBox.SetValue(AutomationProperties.AutomationIdProperty, flagName); Binding binding = new Binding("FlagString"); binding.Mode = BindingMode.TwoWay; binding.Converter = new CheckBoxStringConverter(index); binding.ConverterParameter = panel; checkBox.SetBinding(CheckBox.IsCheckedProperty, binding); index++; } } }
private static CheckBoxClickCommandBehavior GetOrCreateBehavior(CheckBox clicker) { var behavior = clicker.GetValue(ClickCommandBehaviorProperty) as CheckBoxClickCommandBehavior; if (behavior == null) { behavior = new CheckBoxClickCommandBehavior(clicker); clicker.SetValue(ClickCommandBehaviorProperty, behavior); } return behavior; }
/// <summary> /// Generate content for cell by column binding /// </summary> /// <returns>Checkbox element</returns> internal override FrameworkElement GetGeneratedContent() { CheckBox result = new CheckBox(); if (this.Binding != null) { result.SetBinding(CheckBox.IsCheckedProperty, this.Binding); } result.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center); return result; }
private void AddBoxes(int qBoards) { for (int i = 0; i < qBoards; i++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = new GridLength(1, GridUnitType.Auto); boxHolder.RowDefinitions.Add(rowDef); CheckBox box = new CheckBox(); box.IsChecked = true; box.Margin = new Thickness(10); box.HorizontalAlignment = HorizontalAlignment.Left; box.VerticalAlignment = VerticalAlignment.Top; box.Content = string.Format("Board {0}", i); box.Click += CheckBox_Click; selected[i] = true; box.SetValue(Grid.RowProperty, i); boxHolder.Children.Add(box); } }
public ComponentEditor(Component component) { EditorControls = new Dictionary<ComponentProperty, object>(); ComponentUpdated += new ComponentUpdatedDelegate(ComponentEditor_ComponentUpdated); Component = component; ComponentProperty[] propertyInfo = component.Description.Properties; this.DataContext = component; Grid mainGrid = new Grid(); mainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) }); mainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) }); int i = 0; foreach (ComponentProperty info in component.Description.Properties) { mainGrid.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto }); if (info.Type == PropertyType.Boolean) { CheckBox checkbox = new CheckBox(); checkbox.Content = info.DisplayName; checkbox.IsChecked = (bool)component.GetProperty(info).Value; checkbox.Margin = new Thickness(5d); checkbox.Tag = info; checkbox.SetValue(Grid.RowProperty, i); checkbox.SetValue(Grid.ColumnProperty, 0); checkbox.SetValue(Grid.ColumnSpanProperty, 2); checkbox.Checked += new System.Windows.RoutedEventHandler(BoolChanged); checkbox.Unchecked += new System.Windows.RoutedEventHandler(BoolChanged); mainGrid.Children.Add(checkbox); EditorControls.Add(info, checkbox); } else if (info.Type == PropertyType.Decimal) { Label label = new Label(); label.Content = info.DisplayName; label.SetValue(Grid.RowProperty, i); label.SetValue(Grid.ColumnProperty, 0); label.Margin = new Thickness(5d); mainGrid.Children.Add(label); TextBox textbox = new TextBox(); textbox.Tag = info; textbox.Text = component.GetProperty(info).ToString(); textbox.Margin = new Thickness(5d); textbox.SetValue(Grid.RowProperty, i); textbox.SetValue(Grid.ColumnProperty, 1); textbox.TextChanged += new TextChangedEventHandler(DoubleChanged); mainGrid.Children.Add(textbox); EditorControls.Add(info, textbox); } else if (info.Type == PropertyType.Integer) { Label label = new Label(); label.Content = info.DisplayName; label.SetValue(Grid.RowProperty, i); label.SetValue(Grid.ColumnProperty, 0); label.Margin = new Thickness(5d); mainGrid.Children.Add(label); TextBox textbox = new TextBox(); textbox.Margin = new Thickness(5d); textbox.SetValue(Grid.RowProperty, i); textbox.SetValue(Grid.ColumnProperty, 1); textbox.TextChanged += new TextChangedEventHandler(DoubleChanged); mainGrid.Children.Add(textbox); EditorControls.Add(info, textbox); } else if (info.Type == PropertyType.Enum) { Label label = new Label(); label.Content = info.DisplayName; label.SetValue(Grid.RowProperty, i); label.SetValue(Grid.ColumnProperty, 0); label.Margin = new Thickness(5d); mainGrid.Children.Add(label); ComboBox combobox = new ComboBox(); combobox.Margin = new Thickness(5d); combobox.Tag = info; foreach (string option in info.EnumOptions) combobox.Items.Add(option); combobox.SelectedItem = component.GetProperty(info); combobox.SetValue(Grid.RowProperty, i); combobox.SetValue(Grid.ColumnProperty, 1); combobox.SelectionChanged += new SelectionChangedEventHandler(EnumChanged); mainGrid.Children.Add(combobox); EditorControls.Add(info, combobox); } else if (info.Type == PropertyType.String) { Label label = new Label(); label.Content = info.DisplayName; label.SetValue(Grid.RowProperty, i); label.SetValue(Grid.ColumnProperty, 0); label.Margin = new Thickness(5d); mainGrid.Children.Add(label); TextBox textbox = new TextBox(); textbox.Margin = new Thickness(5d); textbox.Tag = info; textbox.Text = component.GetProperty(info).Value as string; textbox.TextChanged += new TextChangedEventHandler(StringChanged); textbox.SetValue(Grid.RowProperty, i); textbox.SetValue(Grid.ColumnProperty, 1); mainGrid.Children.Add(textbox); EditorControls.Add(info, textbox); } i++; } this.Content = mainGrid; this.Loaded += new RoutedEventHandler(AutomaticEditor_Loaded); // Set previous component data }
private CheckBox createCheckBoxForDocument(Document doc, int id) { CheckBox cb = new CheckBox(); cb.Content = doc.Title; if (!String.IsNullOrEmpty(doc.PathName)) { // If the user saves the file, the path where the document is saved is displayed // with a ToolTip, else it displays a message that the file is not saved. cb.ToolTip = doc.PathName; } else { cb.ToolTip = Properties.Resources.DocNotSaved; } ToolTipService.SetShowOnDisabled(cb, true); cb.SetValue(AutomationProperties.AutomationIdProperty, "projectToExportCheckBox" + id); return cb; }
public Graphing() { Settings.Instance.SuspendSave(); try { InitializeComponent(); _startTime = DateTime.Now; _graph.Graph = new Graph(); Settings.Instance.EnsureSeriesToGraphSize(SERIES_MAX); _graph.Graph.Series.Add(new Series { Title = "Roll", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_ROLL], Color = Graph.DefaultColors[0] }); _graph.Graph.Series.Add(new Series { Title = "Pitch", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_PITCH], Color = Graph.DefaultColors[1] }); _graph.Graph.Series.Add(new Series { Title = "Yaw", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_YAW], Color = Graph.DefaultColors[2] }); _graph.Graph.Series.Add(new Series { Title = "Motor Front", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_MOTORFRONT], Color = Graph.DefaultColors[3] }); _graph.Graph.Series.Add(new Series { Title = "Motor Back", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_MOTORBACK], Color = Graph.DefaultColors[4] }); _graph.Graph.Series.Add(new Series { Title = "Motor Left", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_MOTORLEFT], Color = Graph.DefaultColors[5] }); _graph.Graph.Series.Add(new Series { Title = "Motor Right", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_MOTORRIGHT], Color = Graph.DefaultColors[6] }); _graph.Graph.Series.Add(new Series { Title = "User Roll", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_USERROLL], Color = Graph.DefaultColors[7] }); _graph.Graph.Series.Add(new Series { Title = "User Pitch", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_USERPITCH], Color = Graph.DefaultColors[8] }); _graph.Graph.Series.Add(new Series { Title = "User Yaw", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_USERYAW], Color = Graph.DefaultColors[9] }); _graph.Graph.Series.Add(new Series { Title = "User Throttle", Visible = Settings.Instance.SeriesToGraph[SERIES_TELEM_USERTHROTTLE], Color = Graph.DefaultColors[10] }); _graph.Graph.Series.Add(new Series { Title = "IMU Gx", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_GX], Color = Graph.DefaultColors[0] }); _graph.Graph.Series.Add(new Series { Title = "IMU Gy", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_GY], Color = Graph.DefaultColors[1] }); _graph.Graph.Series.Add(new Series { Title = "IMU Gz", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_GZ], Color = Graph.DefaultColors[2] }); _graph.Graph.Series.Add(new Series { Title = "IMU Accel Roll", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_ACCEL_ROLL], Color = Graph.DefaultColors[3] }); _graph.Graph.Series.Add(new Series { Title = "IMU Accel Pitch", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_ACCEL_PITCH], Color = Graph.DefaultColors[4] }); _graph.Graph.Series.Add(new Series { Title = "IMU Compass Yaw", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_COMPASS_YAW], Color = Graph.DefaultColors[5] }); _graph.Graph.Series.Add(new Series { Title = "IMU Roll", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_ROLL], Color = Graph.DefaultColors[6] }); _graph.Graph.Series.Add(new Series { Title = "IMU Pitch", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_PITCH], Color = Graph.DefaultColors[7] }); _graph.Graph.Series.Add(new Series { Title = "IMU Yaw", Visible = Settings.Instance.SeriesToGraph[SERIES_IMU_YAW], Color = Graph.DefaultColors[8] }); for (int i = 0; i < SERIES_MAX; i++) { CheckBox cb = new CheckBox { Content = _graph.Graph.Series[i].Title, IsChecked = Settings.Instance.SeriesToGraph[i] }; cb.Click += Series_CheckBox_Click; cb.SetValue(SeriesIndex, i); _series.Children.Add(cb); } _secondsToGraph.Value = Settings.Instance.SecondsToGraph; } finally { Settings.Instance.ResumeSave(); } }
public static void SetCanSelectedAll(CheckBox obj, bool value) { obj.SetValue(CanSelectedAllProperty, value); }
/// <summary> /// Render a singleton item into a ListBoxItem /// </summary> /// <param name="item">Item to render</param> /// <returns>ListBoxItem corresponding to the Item</returns> private ListBoxItem RenderItemAsSingleton(Item item) { // get the icon for the itemtype ItemType itemType = null; string icon = null; if (ItemType.ItemTypes.TryGetValue(item.ItemTypeID, out itemType)) icon = itemType.Icon; FrameworkElement element; ListBoxItem listBoxItem = new ListBoxItem() { Tag = item }; StackPanel sp = new StackPanel() { Margin = new Thickness(0, -5, 0, 0), Width = 432d }; listBoxItem.Content = sp; // first line (priority icon, checkbox / icon, name) Grid itemLineOne = new Grid(); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); itemLineOne.Children.Add(element = new Image() { Source = new BitmapImage(new Uri(item.PriorityIcon, UriKind.Relative)), Margin = new Thickness(0, 2, 0, 0) }); element.SetValue(Grid.ColumnProperty, 0); // render a checkbox if has Complete field if (itemType != null && itemType.HasField(FieldNames.Complete)) { itemLineOne.Children.Add(element = new CheckBox() { IsChecked = (item.Complete == null ? false : item.Complete), Tag = item.ID }); element.SetValue(Grid.ColumnProperty, 1); ((CheckBox)element).Click += new RoutedEventHandler(checkBoxClickEvent); } else { // render an icon if one exists if (icon != null) { if (icon.StartsWith("/Images/") == false && icon.StartsWith("http") == false && icon.StartsWith("www.") == false) icon = "/Images/" + icon; itemLineOne.Children.Add(element = new Image() { Source = new BitmapImage(new Uri(icon, UriKind.RelativeOrAbsolute)), Width = 48, Height = 48, Margin = new Thickness(5, 11, 16, 8) }); element.SetValue(Grid.ColumnProperty, 1); } // render a picture if one exists // this picture will layer on top of the existing icon - in case the picture is unavailable (e.g. disconnected) var picFV = item.GetFieldValue(FieldNames.Picture, false); if (picFV != null && !String.IsNullOrEmpty(picFV.Value)) { icon = picFV.Value; if (icon.StartsWith("/Images/") == false && icon.StartsWith("http") == false && icon.StartsWith("www.") == false) icon = "/Images/" + icon; itemLineOne.Children.Add(element = new Image() { Source = new BitmapImage(new Uri(icon, UriKind.RelativeOrAbsolute)), Width = 48, Height = 48, Margin = new Thickness(5, 11, 16, 8) }); element.SetValue(Grid.ColumnProperty, 1); } } itemLineOne.Children.Add(element = new TextBlock() { Text = item.Name, Style = (Style)App.Current.Resources["PhoneTextLargeStyle"], Foreground = new SolidColorBrush(GetDisplayColor(item.NameDisplayColor)), Margin = new Thickness(0, 12, 0, 0) }); element.SetValue(Grid.ColumnProperty, 2); sp.Children.Add(itemLineOne); // second line (duedate, tags) Grid itemLineTwo = new Grid(); itemLineTwo.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineTwo.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); itemLineTwo.Children.Add(element = new TextBlock() { Text = item.DueDisplay, FontSize = (double)App.Current.Resources["PhoneFontSizeNormal"], Foreground = new SolidColorBrush(GetDisplayColor(item.DueDisplayColor)), Margin = new Thickness(32, -17, 0, 0) }); element.SetValue(Grid.ColumnProperty, 0); // render tag panel if (item.Tags != null) { StackPanel tagStackPanel = new StackPanel() { Margin = new Thickness(32, -17, 0, 0), Orientation = System.Windows.Controls.Orientation.Horizontal, HorizontalAlignment = System.Windows.HorizontalAlignment.Right }; tagStackPanel.SetValue(Grid.ColumnProperty, 1); foreach (var tag in item.Tags) { HyperlinkButton button; tagStackPanel.Children.Add(button = new HyperlinkButton() { ClickMode = ClickMode.Release, Content = tag.Name, FontSize = (double)App.Current.Resources["PhoneFontSizeNormal"], Foreground = new SolidColorBrush(GetDisplayColor(App.ViewModel.Constants.LookupColor(tag.ColorID))), Tag = tag.ID }); button.Click += tagClickEvent; } itemLineTwo.Children.Add(tagStackPanel); } sp.Children.Add(itemLineTwo); // return the new ListBoxItem return listBoxItem; }
//自动提交订单 private async void tsAutoOrder_Checked(object sender, RoutedEventArgs e) { if ((bool)tsAutoOrder.IsChecked) { gridContacts.Children.Clear(); gridTickets.Children.Clear(); gridSeatTypes.Children.Clear(); progressRingAnima.IsActive = true; int tickCount = await SearchTickets(); if (tickCount > 0) { borderAutoSubmitOrder.Visibility = Visibility.Visible; gridOpacity.Visibility = Visibility.Visible; //乘客 lblStatusMsg.Content = "加载乘客中..."; bool result = await ticketHelper.SaveContacts(); if (result) { List<Contacts> contacts = ticketHelper.ReadContacts("Contact"); int cRow = (int)Math.Ceiling((double)contacts.Count / 6), cCell = 6; while (cRow-- > 0) { gridContacts.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) }); } while (cCell-- > 0) { gridContacts.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); } if (contacts.Count > 0) { int r = 0, c = 0; for (int i = 0; i < contacts.Count; i++) { CheckBox autoChkContact = new CheckBox() { Content = contacts[i].PassengerName, Name = "chk" + contacts[i].Code, Height = 18, Tag = contacts[i].PassengerType + "," + contacts[i].PassengerName + "," + contacts[i].PassengerIdTypeCode + "," + contacts[i].PassengerIdNo + "," + contacts[i].Mobile, Uid = contacts[i].PassengerName + "," + contacts[i].PassengerIdTypeCode + "," + contacts[i].PassengerIdNo + "," + contacts[i].PassengerType }; autoChkContact.Click += autoChkContact_Click; gridContacts.Children.Add(autoChkContact); if (i > 0) { if ((i % 6) == 0) { r += 1; c = 0; } else { c++; } } autoChkContact.SetValue(Grid.RowProperty, r); autoChkContact.SetValue(Grid.ColumnProperty, c); } } } //车次 lblStatusMsg.Content = "乘客加载完成,正在加载车次中..."; List<Tickets> lstTickets = gridTrainList.ItemsSource as List<Tickets>; //dgTicket.ItemsSource = lstTickets; int tRow = (int)Math.Ceiling((double)lstTickets.Count() / 6), tCell = 6; while (tRow-- > 0) { gridTickets.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(15) }); } while (tCell-- > 0) { gridTickets.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); } int tR = 0, tC = 0; for (int t = 0; t < lstTickets.Count(); t++) { string swz = "无--".Contains(lstTickets[t].SWZNum) ? "" : "商务座"; string tdz = "无--".Contains(lstTickets[t].TZNum) ? "" : "特等座"; string ydz = "无--".Contains(lstTickets[t].ZYNum) ? "" : "一等座"; string edz = "无--".Contains(lstTickets[t].ZENum) ? "" : "二等座"; string gjrw = "无--".Contains(lstTickets[t].GRNum) ? "" : "高级软卧"; string rw = "无--".Contains(lstTickets[t].RWNum) ? "" : "软卧"; string yw = "无--".Contains(lstTickets[t].YWNum) ? "" : "硬卧"; string rz = "无--".Contains(lstTickets[t].RZNum) ? "" : "软座"; string yz = "无--".Contains(lstTickets[t].YZNum) ? "" : "硬座"; string wz = "无--".Contains(lstTickets[t].WZNum) ? "" : "无座"; CheckBox chkTicket = new CheckBox() { Name = "chk" + lstTickets[t].TrainNo, Content = lstTickets[t].TrainName, Tag = swz + "," + tdz + "," + ydz + "," + edz + "," + gjrw + "," + rw + "," + yw + "," + rz + "," + yz + "," + wz, ToolTip = "起止时间:【" + lstTickets[t].StartTime + "-" + lstTickets[t].ArriveTime + "】\n历时:【" + lstTickets[t].LiShi + "】", Uid = lstTickets[t].SecretStr + "," + lstTickets[t].YPInfo }; chkTicket.Click += chkTicket_Click; gridTickets.Children.Add(chkTicket); if (t > 0) { if ((t % 6) == 0) { tR += 1; tC = 0; } else { tC++; } } chkTicket.SetValue(Grid.RowProperty, tR); chkTicket.SetValue(Grid.ColumnProperty, tC); } lblStatusMsg.Content = "预选信息加载完成"; progressRingAnima.IsActive = false; } } }
void cnvPaint_Drop(object sender, DragEventArgs e) { try { if (e.Data.GetData(typeof(Button)) != null) { if (((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Button btn = new Button(); btn.Height = 25; btn.Width = 100; btn.Content = "Button"; btn.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown); btn.SetValue(Canvas.LeftProperty, 10.0); btn.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(btn); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent).GetType() == typeof(ctlPOD)) { if (currentControl.rect.Visibility == Visibility.Visible) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } } else if (e.Data.GetData(typeof(TabControl)) != null) { if (((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TabControl lbl = new TabControl(); //lbl.Content = "TabControl"; lbl.HorizontalContentAlignment = HorizontalAlignment.Center; lbl.Height = 25; lbl.Width = 100; lbl.PreviewMouseDown += new MouseButtonEventHandler(tabDrag999_PreviewMouseDown); lbl.SetValue(Canvas.LeftProperty, 10.0); lbl.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.cnvPOD.Children.Add(lbl); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown); objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(Label)) != null) { if (((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Label lbl = new Label(); lbl.Content = "Label"; lbl.HorizontalContentAlignment = HorizontalAlignment.Center; lbl.Height = 25; lbl.Width = 100; lbl.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown); lbl.SetValue(Canvas.LeftProperty, 10.0); lbl.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.cnvPOD.Children.Add(lbl); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown); objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(TextBox)) != null) { if (((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TextBox txt = new TextBox(); txt.IsReadOnly = true; txt.Cursor = Cursors.Arrow; txt.Height = 25; txt.Width = 100; txt.Text = "TextBox"; txt.MouseDown += new MouseButtonEventHandler(txt_MouseDown); txt.PreviewMouseDown += new MouseButtonEventHandler(txtDrag_PreviewMouseDown); txt.SetValue(Canvas.LeftProperty, 10.0); txt.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(txt); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ComboBox)) != null) { if (((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ComboBox cmb = new ComboBox(); cmb.Cursor = Cursors.Arrow; cmb.Height = 25; cmb.Width = 100; cmb.Text = "ComboBox"; cmb.PreviewMouseDown += new MouseButtonEventHandler(cmb_PreviewMouseDown); cmb.SetValue(Canvas.LeftProperty, 10.0); cmb.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(cmb); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ListBox)) != null) { if (((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ListBox lst = new ListBox(); lst.Cursor = Cursors.Arrow; lst.Height = 25; lst.Width = 100; lst.PreviewMouseDown += new MouseButtonEventHandler(lst_PreviewMouseDown); lst.SetValue(Canvas.LeftProperty, 10.0); lst.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(lst); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(CheckBox)) != null) { if (((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); CheckBox chk = new CheckBox(); chk.Cursor = Cursors.Arrow; chk.Height = 25; chk.Width = 100; chk.Content = "Check Box"; chk.PreviewMouseDown += new MouseButtonEventHandler(chk_PreviewMouseDown); chk.SetValue(Canvas.LeftProperty, 10.0); chk.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(chk); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(RadioButton)) != null) { if (((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); RadioButton rad = new RadioButton(); rad.Cursor = Cursors.Arrow; rad.Height = 25; rad.Width = 100; rad.Content = "Radio Button"; rad.PreviewMouseDown += new MouseButtonEventHandler(rad_PreviewMouseDown); rad.SetValue(Canvas.LeftProperty, 10.0); rad.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(rad); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } newDrag = 1; r1.Visibility = Visibility.Collapsed; MyPropGrid.ControlToBind = currentControl; } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "cnvPaint_Drop()", "ctlCRMDesigner.xaml.cs"); } }
public static void SetCommand(CheckBox clicker, ICommand command) { clicker.SetValue(CommandProperty, command); }
//Sets up the controls for the custom control private void InitializeControl() { int i = 0; foreach (CCustomLine cl in this.CustomFields.CustomLines) { //Add new row to the grid RowDefinition rd = new RowDefinition(); rd.MinHeight = 30; rd.MaxHeight = 30; ControlGrid.RowDefinitions.Add(rd); System.Windows.Controls.TextBlock tb = new TextBlock(); tb.SetValue(Grid.RowProperty, i); tb.SetValue(Grid.ColumnProperty, 0); tb.TextAlignment = TextAlignment.Right; tb.Margin = new Thickness(3); tb.Text = cl.Caption; ControlGrid.Children.Add(tb); switch (cl.DataType) { case CCustomLine.CustDataType.cdText: if (cl.IsList) { System.Windows.Controls.ComboBox cbx = new ComboBox(); cbx.SetValue(Grid.RowProperty, i); cbx.SetValue(Grid.ColumnProperty, 1); cbx.Margin = new Thickness(3); cbx.Tag = cl.Caption; cbx.SelectionChanged += CustomDataChanged; foreach (string sl in cl.PickList) { cbx.Items.Add(sl); } ControlGrid.Children.Add(cbx); } else { System.Windows.Controls.TextBox tbx = new TextBox(); tbx.SetValue(Grid.RowProperty, i); tbx.SetValue(Grid.ColumnProperty, 1); tbx.Margin = new Thickness(3); tbx.Tag = cl.Caption; tbx.Text = cl.Caption; tbx.TextChanged += CustomDataChanged; ControlGrid.Children.Add(tbx); } break; case CCustomLine.CustDataType.cdDate: System.Windows.Controls.DatePicker dtp = new DatePicker(); dtp.SetValue(Grid.RowProperty, i); dtp.SetValue(Grid.ColumnProperty, 1); dtp.Margin = new Thickness(3); dtp.Tag = cl.Caption; dtp.SelectedDateChanged += CustomDataChanged; ControlGrid.Children.Add(dtp); break; case CCustomLine.CustDataType.cdInteger: Xceed.Wpf.Toolkit.IntegerUpDown iud = new IntegerUpDown(); iud.SetValue(Grid.RowProperty, i); iud.SetValue(Grid.ColumnProperty, 1); iud.Margin = new Thickness(3); iud.Tag = cl.Caption; iud.ValueChanged += CustomDataChanged; ControlGrid.Children.Add(iud); break; case CCustomLine.CustDataType.cdNumber: Xceed.Wpf.Toolkit.CalculatorUpDown dud = new CalculatorUpDown(); dud.SetValue(Grid.RowProperty, i); dud.SetValue(Grid.ColumnProperty, 1); dud.Margin = new Thickness(3); dud.Tag = cl.Caption; dud.ValueChanged += CustomDataChanged; ControlGrid.Children.Add(dud); break; case CCustomLine.CustDataType.cdCurrency: Xceed.Wpf.Toolkit.CalculatorUpDown cud = new CalculatorUpDown(); cud.SetValue(Grid.RowProperty, i); cud.SetValue(Grid.ColumnProperty, 1); cud.Margin = new Thickness(3); cud.Tag = cl.Caption; cud.FormatString = "C2"; cud.ValueChanged += CustomDataChanged; ControlGrid.Children.Add(cud); break; case CCustomLine.CustDataType.cdBoolean: System.Windows.Controls.CheckBox chkb = new CheckBox(); chkb.SetValue(Grid.RowProperty, i); chkb.SetValue(Grid.ColumnProperty, 1); chkb.Margin = new Thickness(3); //Do we need this? chkb.Tag = cl.Caption; chkb.Checked += CustomDataChanged; ControlGrid.Children.Add(chkb); break; case CCustomLine.CustDataType.cdBusinessLink: case CCustomLine.CustDataType.cdInspectorLink: System.Windows.Controls.TextBlock LinkTB = new TextBlock(); LinkTB.SetValue(Grid.RowProperty, i); LinkTB.SetValue(Grid.ColumnProperty, 1); LinkTB.Margin = new Thickness(3); //Do we need this? LinkTB.Tag = cl.Caption; ControlGrid.Children.Add(LinkTB); break; } i++; } }
void cnvPaint_Drop(object sender, DragEventArgs e) { if (e.Data.GetData(typeof(Button)) != null) { if (((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Button btn = new Button(); btn.Height = 25; btn.Width = 100; btn.Content = "Button"; btn.Background = Brushes.Transparent; btn.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown); btn.SetValue(Canvas.LeftProperty, 10.0); btn.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.cnvPOD.Children.Add(btn); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent).GetType() == typeof(ctlPOD)) { //v // if (currentControl.rect.Visibility == Visibility.Visible) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } } else if (e.Data.GetData(typeof(Label)) != null) { if (((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Label lbl = new Label(); lbl.Content = "Label"; lbl.Background = Brushes.Transparent; lbl.Foreground = Brushes.Black ; lbl.HorizontalContentAlignment = HorizontalAlignment.Center; lbl.Height = 25; lbl.Width = 100; lbl.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown); lbl.SetValue(Canvas.LeftProperty, 10.0); lbl.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.cnvPOD.Children.Add(lbl); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown); objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(TextBox)) != null) { if (((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TextBox txt = new TextBox(); txt.Cursor = Cursors.Arrow; txt.Background = Brushes.Transparent; txt.Height = 25; txt.Width = 100; txt.Text = "TextBox"; txt.MouseDown += new MouseButtonEventHandler(txt_MouseDown); txt.PreviewMouseDown += new MouseButtonEventHandler(txtDrag_PreviewMouseDown); txt.SetValue(Canvas.LeftProperty, 10.0); txt.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(txt); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(TextBlock)) != null) { if (((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TextBlock txb = new TextBlock(); txb.Cursor = Cursors.Arrow; txb.Height = 25; txb.Width = 100; txb.Background = Brushes.Transparent; txb.TextWrapping = TextWrapping.Wrap; txb.Text = "TextBlock"; txb.PreviewMouseDown += new MouseButtonEventHandler(txbDrag999_PreviewMouseDown); txb.SetValue(Canvas.LeftProperty, 10.0); txb.SetValue(Canvas.TopProperty, 10.0); txb.Foreground = Brushes.Black; ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(txb); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ComboBox)) != null) { if (((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ComboBox cmb = new ComboBox(); cmb.Cursor = Cursors.Arrow; cmb.Height = 25; cmb.Width = 100; cmb.Background = Brushes.Transparent; cmb.Text = "ComboBox"; cmb.PreviewMouseDown += new MouseButtonEventHandler(cmb_PreviewMouseDown); cmb.SetValue(Canvas.LeftProperty, 10.0); cmb.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(cmb); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ListBox)) != null) { if (((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ListBox lst = new ListBox(); lst.Cursor = Cursors.Arrow; lst.Height = 25; lst.Width = 100; lst.Background = Brushes.Transparent; lst.PreviewMouseDown += new MouseButtonEventHandler(lst_PreviewMouseDown); lst.SetValue(Canvas.LeftProperty, 10.0); lst.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(lst); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(CheckBox)) != null) { if (((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); CheckBox chk = new CheckBox(); chk.Cursor = Cursors.Arrow; chk.Height = 25; chk.Width = 100; chk.Content = "Check Box"; chk.Background = Brushes.Transparent; chk.PreviewMouseDown += new MouseButtonEventHandler(chk_PreviewMouseDown); chk.SetValue(Canvas.LeftProperty, 10.0); chk.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(chk); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(RadioButton)) != null) { if (((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); RadioButton rad = new RadioButton(); rad.Cursor = Cursors.Arrow; rad.Height = 25; rad.Width = 100; rad.Content = "Radio Button"; rad.Background = Brushes.Transparent; rad.PreviewMouseDown += new MouseButtonEventHandler(rad_PreviewMouseDown); rad.SetValue(Canvas.LeftProperty, 10.0); rad.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(rad); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } newDrag = 1; r1.Visibility = Visibility.Collapsed; MyPropGrid.ControlToBind = currentControl; }
private static void CreateStars(RateControl rat, int? amount) { if (amount == null) { amount = 1; } // Do the cleanup for the old stuff foreach (CheckBox box in rat.stars) { rat.LayoutRoot.Children.Remove(box); } rat.stars.Clear(); List<ColumnDefinition> columnDefinitionsToRemove = new List<ColumnDefinition>(); foreach (ColumnDefinition def in rat.LayoutRoot.ColumnDefinitions) { columnDefinitionsToRemove.Add(def); } foreach (ColumnDefinition def in columnDefinitionsToRemove) { rat.LayoutRoot.ColumnDefinitions.Remove(def); } rat.Rating = 0; // Create the new controls for (int i = 0; i < amount; ++i) { rat.LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition()); CheckBox check = new CheckBox(); check.Name = "check" + i.ToString(); check.SetValue(Grid.ColumnProperty, i); check.HorizontalAlignment = HorizontalAlignment.Left; check.Checked += new RoutedEventHandler(OnCheck); check.Unchecked += new RoutedEventHandler(OnCheck); rat.stars.Add(check); rat.LayoutRoot.Children.Add(check); } }
/// <summary> /// Render a task into a ListBoxItem /// </summary> /// <param name="t">Task to render</param> /// <returns>ListBoxItem corresponding to the Task</returns> private ListBoxItem RenderTask(Task t) { FrameworkElement element; ListBoxItem listBoxItem = new ListBoxItem() { Tag = t }; StackPanel sp = new StackPanel() { Margin = new Thickness(0, -5, 0, 0), Width = 432d }; listBoxItem.Content = sp; // first line (priority icon, checkbox, name) Grid itemLineOne = new Grid(); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineOne.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); itemLineOne.Children.Add(element = new Image() { Source = new BitmapImage(new Uri(t.PriorityIDIcon, UriKind.Relative)), Margin = new Thickness(0, 2, 0, 0) }); element.SetValue(Grid.ColumnProperty, 0); itemLineOne.Children.Add(element = new CheckBox() { IsChecked = t.Complete, Tag = t.ID }); element.SetValue(Grid.ColumnProperty, 1); ((CheckBox)element).Click += new RoutedEventHandler(checkBoxClickEvent); itemLineOne.Children.Add(element = new TextBlock() { Text = t.Name, Style = (Style)App.Current.Resources["PhoneTextLargeStyle"], Foreground = new SolidColorBrush(GetDisplayColor(t.NameDisplayColor)), Margin = new Thickness(0, 12, 0, 0) }); element.SetValue(Grid.ColumnProperty, 2); sp.Children.Add(itemLineOne); // second line (duedate, tags) Grid itemLineTwo = new Grid(); itemLineTwo.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); itemLineTwo.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); itemLineTwo.Children.Add(element = new TextBlock() { Text = t.DueDisplay, FontSize = (double)App.Current.Resources["PhoneFontSizeNormal"], Foreground = new SolidColorBrush(GetDisplayColor(t.DueDisplayColor)), Margin = new Thickness(32, -17, 0, 0) }); element.SetValue(Grid.ColumnProperty, 0); // render tag panel if (t.Tags != null) { StackPanel tagStackPanel = new StackPanel() { Margin = new Thickness(32, -17, 0, 0), Orientation = System.Windows.Controls.Orientation.Horizontal, HorizontalAlignment = System.Windows.HorizontalAlignment.Right }; tagStackPanel.SetValue(Grid.ColumnProperty, 1); foreach (var tag in t.Tags) { HyperlinkButton button; tagStackPanel.Children.Add(button = new HyperlinkButton() { ClickMode = ClickMode.Release, Content = tag.Name, FontSize = (double)App.Current.Resources["PhoneFontSizeNormal"], Foreground = new SolidColorBrush(GetDisplayColor(tag.Color)), Tag = tag.ID }); button.Click += tagClickEvent; } itemLineTwo.Children.Add(tagStackPanel); } sp.Children.Add(itemLineTwo); // return the new ListBoxItem return listBoxItem; }
void cnvPaint_Drop(object sender, DragEventArgs e) { try { if (e.Data.GetData(typeof(Button)) != null) { if (((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Button btn = new Button(); btn.Height = 25; btn.Width = 100; btn.Content = "Button"; btn.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown); btn.SetValue(Canvas.LeftProperty, 10.0); btn.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(btn); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent).GetType() == typeof(ctlPOD)) { if (currentControl.rect.Visibility == Visibility.Visible) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } } else if (e.Data.GetData(typeof(TabControl)) != null) { if (((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TabControl lbl = new TabControl(); //lbl.Content = "TabControl"; lbl.HorizontalContentAlignment = HorizontalAlignment.Center; lbl.Height = 25; lbl.Width = 100; lbl.PreviewMouseDown += new MouseButtonEventHandler(tabDrag999_PreviewMouseDown); lbl.SetValue(Canvas.LeftProperty, 10.0); lbl.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.cnvPOD.Children.Add(lbl); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown); objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TabControl)e.Data.GetData(typeof(TabControl))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(Label)) != null) { if (((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); Label lbl = new Label(); lbl.Content = "Label"; lbl.HorizontalContentAlignment = HorizontalAlignment.Center; lbl.Height = 25; lbl.Width = 100; lbl.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown); lbl.SetValue(Canvas.LeftProperty, 10.0); lbl.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.cnvPOD.Children.Add(lbl); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown); objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(TextBox)) != null) { if (((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); TextBox txt = new TextBox(); txt.IsReadOnly = true; txt.Cursor = Cursors.Arrow; txt.Height = 25; txt.Width = 100; txt.Text = "TextBox"; txt.MouseDown += new MouseButtonEventHandler(txt_MouseDown); txt.PreviewMouseDown += new MouseButtonEventHandler(txtDrag_PreviewMouseDown); txt.SetValue(Canvas.LeftProperty, 10.0); txt.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(txt); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ComboBox)) != null) { if (((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ComboBox cmb = new ComboBox(); cmb.Cursor = Cursors.Arrow; cmb.Height = 25; cmb.Width = 100; cmb.Text = "ComboBox"; cmb.PreviewMouseDown += new MouseButtonEventHandler(cmb_PreviewMouseDown); cmb.SetValue(Canvas.LeftProperty, 10.0); cmb.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(cmb); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(ListBox)) != null) { if (((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); ListBox lst = new ListBox(); lst.Cursor = Cursors.Arrow; lst.Height = 25; lst.Width = 100; lst.PreviewMouseDown += new MouseButtonEventHandler(lst_PreviewMouseDown); lst.SetValue(Canvas.LeftProperty, 10.0); lst.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(lst); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(CheckBox)) != null) { if (((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); CheckBox chk = new CheckBox(); chk.Cursor = Cursors.Arrow; chk.Height = 25; chk.Width = 100; chk.Content = "Check Box"; chk.PreviewMouseDown += new MouseButtonEventHandler(chk_PreviewMouseDown); chk.SetValue(Canvas.LeftProperty, 10.0); chk.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(chk); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } else if (e.Data.GetData(typeof(RadioButton)) != null) { if (((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Name.ToString() == "cnvControls") { Point p = e.GetPosition((IInputElement)cnvPaint); RadioButton rad = new RadioButton(); rad.Cursor = Cursors.Arrow; rad.Height = 25; rad.Width = 100; rad.Content = "Radio Button"; rad.PreviewMouseDown += new MouseButtonEventHandler(rad_PreviewMouseDown); rad.SetValue(Canvas.LeftProperty, 10.0); rad.SetValue(Canvas.TopProperty, 10.0); ctlPOD objPOD = new ctlPOD(); objPOD.AllowDrop = true; objPOD.Height = 25; objPOD.Width = 100; objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown); objPOD.SetValue(Canvas.LeftProperty, p.X); objPOD.SetValue(Canvas.TopProperty, p.Y); MyPropGrid.ControlToBind = objPOD; objPOD.cnvPOD.Children.Add(rad); currentControl = objPOD; cnvPaint.Children.Add(objPOD); } else if ((((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent).GetType() == typeof(ctlPOD)) { Point p = e.GetPosition((IInputElement)cnvPaint); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X); ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y); } } newDrag = 1; r1.Visibility = Visibility.Collapsed; MyPropGrid.ControlToBind = currentControl; } catch (Exception ex) { ex.Data.Add("My Key", "VMukti--:--VmuktiModules--:--Call Center--:--CRMDesigner--:--CRMDesigner.Presentation--:--ctlCRMDesigner.xaml.cs--:--cnvPaint_Drop()--"); //ClsException.LogError(ex); //ClsException.WriteToErrorLogFile(ex); System.Text.StringBuilder sb = new StringBuilder(); sb.AppendLine(ex.Message); sb.AppendLine(); sb.AppendLine("StackTrace : " + ex.StackTrace); sb.AppendLine(); sb.AppendLine("Location : " + ex.Data["My Key"].ToString()); sb.AppendLine(); sb1 = CreateTressInfo(); sb.Append(sb1.ToString()); VMuktiAPI.ClsLogging.WriteToTresslog(sb); } }
//自动提交订单--单击车次 void chkTicket_Click(object sender, RoutedEventArgs e) { List<string> lstTickets = new List<string>(); string strSeatTypes = ""; foreach (var chkItem in gridTickets.Children) { if (chkItem is CheckBox) { CheckBox chkTicket = chkItem as CheckBox; if ((bool)chkTicket.IsChecked) { lstTickets.Add(chkTicket.Content.ToString()); if (lstTickets.Count() < 5) { strSeatTypes += chkTicket.Tag.ToString() + ","; } } } } if (lstTickets.Count() > 5) { MessageBox.Show("选择车次数不能超过5个", "消息"); CheckBox chkObj = e.Source as CheckBox; chkObj.IsChecked = false; return; } var arrSeatType = strSeatTypes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Dictionary<string, string> dicSeatTypes = new Dictionary<string, string>(); List<string> lstSeat = new List<string>(); for (int i = 0; i < arrSeatType.Count(); i++) { lstSeat.Add(arrSeatType[i]); } lstSeat = lstSeat.Distinct().ToList(); dicSeatTypes.Clear(); for (int s = 0; s < lstSeat.Count(); s++) { string seatValue = lstSeat[s] == "商务座" ? "9" : lstSeat[s] == "特等座" ? "P" : lstSeat[s] == "一等座" ? "M" : lstSeat[s] == "二等座" ? "O" : lstSeat[s] == "高级软卧" ? "6" : lstSeat[s] == "软卧" ? "4" : lstSeat[s] == "硬卧" ? "3" : lstSeat[s] == "软座" ? "2" : lstSeat[s] == "硬座" ? "1" : lstSeat[s] == "无座" ? "1" : "1"; dicSeatTypes.Add(lstSeat[s], seatValue); } int sRow = (int)Math.Ceiling((double)lstSeat.Count() / 6), sCell = 6; while (sRow-- > 0) { gridSeatTypes.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(15) }); } while (sCell-- > 0) { gridSeatTypes.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); } gridSeatTypes.Children.Clear(); int sR = 0, sC = 0, sT = 0; foreach (var d in dicSeatTypes) { CheckBox chkSeatType = new CheckBox() { Name = "chk" + d.Value, Content = d.Key, Tag = d.Value }; chkSeatType.Click += chkSeatType_Click; gridSeatTypes.Children.Add(chkSeatType); if (sT > 0) { if (sT % 6 == 0) { sR += 1; sC = 0; } else { sC++; } } chkSeatType.SetValue(Grid.RowProperty, sR); chkSeatType.SetValue(Grid.ColumnProperty, sC); sT++; } }
public virtual void AddConfigUI(Grid grid) { TextBlock label; #region Header grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid g = new Grid(); g.ColumnDefinitions.Add(new ColumnDefinition()); g.ColumnDefinitions.Add(new ColumnDefinition()); g.RowDefinitions.Add(new RowDefinition()); label = new TextBlock() { Text = DisplayName ?? Name, VerticalAlignment = System.Windows.VerticalAlignment.Center, Margin = new Thickness(2,10,2,2), FontWeight = FontWeights.Bold, TextTrimming = TextTrimming.WordEllipsis }; g.Children.Add(label); if (Required) { label = new TextBlock() { Text = Resources.Strings.Required, VerticalAlignment = System.Windows.VerticalAlignment.Center, HorizontalAlignment = System.Windows.HorizontalAlignment.Right, Margin = new Thickness(2), FontWeight = FontWeights.Light, FontStyle = FontStyles.Italic }; label.SetValue(Grid.ColumnProperty, 1); g.Children.Add(label); } g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); g.SetValue(Grid.ColumnSpanProperty, 2); grid.Children.Add(g); #endregion #region Type grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); label = new TextBlock() { Text = Resources.Strings.LabelType, Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); grid.Children.Add(label); label = new TextBlock() { Text = Type.ToString(), Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); label.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(label); #endregion #region Label grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); label = new TextBlock() { Text = Resources.Strings.LabelLabel, Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); grid.Children.Add(label); TextBox labelTextBox = new TextBox() { Text = Label == null ? string.Empty : Label, Margin = new Thickness(2), HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, }; labelTextBox.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); labelTextBox.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(labelTextBox); labelTextBox.TextChanged += (s, e) => { Label = labelTextBox.Text; }; #endregion if (Input) { #region Tooltip grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); label = new TextBlock() { Text = Resources.Strings.LabelTooltip, Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); grid.Children.Add(label); TextBox tbToolTip = new TextBox() { Margin = new Thickness(2), HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, }; if (!string.IsNullOrEmpty(ToolTip)) tbToolTip.Text = ToolTip; tbToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); tbToolTip.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(tbToolTip); tbToolTip.TextChanged += (s, e) => { ToolTip = tbToolTip.Text; }; #endregion #region ShownAtRuntime grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); label = new TextBlock() { Text = Resources.Strings.LabelShowParameter, Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); grid.Children.Add(label); CheckBox chb = new CheckBox() { IsChecked = ShownAtRunTime, Margin = new Thickness(2) }; chb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); chb.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(chb); chb.Checked += (s, e) => { ShownAtRunTime = true; }; chb.Unchecked += (s, e) => { ShownAtRunTime = false; }; #endregion #region Default Value if (Type != GPParameterType.FeatureLayer && Type != GPParameterType.MultiValueString) { grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); label = new TextBlock() { Text = Resources.Strings.LabelDefaultValue, Margin = new Thickness(2), VerticalAlignment = System.Windows.VerticalAlignment.Center }; label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1); grid.Children.Add(label); ParameterBase paramUI = ParameterFactory.Create(this, null); paramUI.AddUI(grid); paramUI.CanExecuteChanged += (a, b) => { this.DefaultValue = paramUI.Value; }; } #endregion } }
//加载乘客 private async Task GetContacts() { gContacts.Children.Clear(); lblStatusMsg.Content = "加载乘客中..."; bool result = await ticketHelper.SaveContacts(); if (result) { List<Contacts> contacts = ticketHelper.ReadContacts("Contact"); int row = (int)Math.Ceiling((double)contacts.Count / 5), cell = 5; while (row-- > 0) { gContacts.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) }); } while (cell-- > 0) { gContacts.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength() }); } if (contacts.Count > 0) { int r = 0, c = 0; for (int i = 0; i < contacts.Count; i++) { CheckBox chkContact = new CheckBox() { Content = contacts[i].PassengerName, Name = "chk" + contacts[i].Code, Height = 18, Tag = contacts[i].PassengerTypeName + "#" + contacts[i].PassengerName + "#" + contacts[i].PassengerIdTypeName + "#" + contacts[i].PassengerIdNo + "#" + contacts[i].Mobile }; chkContact.Click += chkContact_Click; gContacts.Children.Add(chkContact); if (i > 0) { if ((i % 5) == 0) { r += 1; c = 0; } else { c++; } } chkContact.SetValue(Grid.RowProperty, r); chkContact.SetValue(Grid.ColumnProperty, c); } } } lblStatusMsg.Content = "加载乘客完成..."; }
private void _addJob(Grid grid, Job job) { CheckBox box = new CheckBox(); box.Margin = new Thickness(7, 6, 7, 6); box.Content = job == JobList.BardDancer ? Methods.Aggregate(job.Names, ", ") : job.Name; //box.Content = (job == JobList.BardDancer || job == JobList.Kangerou) ? Methods.Aggregate(job.Names, ", ") : job.Name; box.SetValue(Grid.RowProperty, grid.RowDefinitions.Count); box.VerticalAlignment = VerticalAlignment.Center; box.Tag = job; box.Checked += delegate { _update(); }; box.Unchecked += delegate { _update(); }; _boxes.Add(box); grid.RowDefinitions.Add(new RowDefinition()); grid.Children.Add(box); }
// Should be called whenever cb_ModSelector.SelectedIndex is changed. private void LoadProcessSteps() { // If SelectedIndex is -1, don't try to read tasks for a nonexistant mod. if (cb_ModSelector.SelectedIndex == -1) { // Do nothing. } else { // Read tasks for selected mod into GlobalVars. GetAllTasksForMod(GlobalVars.SelectedContract, GlobalVars.mList[cb_ModSelector.SelectedIndex].i_ModID); } // Clear any previous row definitions. grd_MainGrid.Children.Clear(); grd_MainGrid.RowDefinitions.Clear(); // Add first row for the header. var header = new RowDefinition(); header.Height = GridLength.Auto; grd_MainGrid.RowDefinitions.Add(header); // Add header labels. var col1 = new Label(); col1.Content = "Step"; col1.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col1.SetValue(Grid.RowProperty, 0); col1.SetValue(Grid.ColumnProperty, 1); grd_MainGrid.Children.Add(col1); var col2 = new Label(); col2.Content = "Title"; col2.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col2.SetValue(Grid.RowProperty, 0); col2.SetValue(Grid.ColumnProperty, 2); grd_MainGrid.Children.Add(col2); var col3 = new Label(); col3.Content = "Description"; col3.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col3.SetValue(Grid.RowProperty, 0); col3.SetValue(Grid.ColumnProperty, 3); grd_MainGrid.Children.Add(col3); var col4 = new Label(); col4.Content = "Due Date"; col4.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col4.SetValue(Grid.RowProperty, 0); col4.SetValue(Grid.ColumnProperty, 4); grd_MainGrid.Children.Add(col4); var col5 = new Label(); col5.Content = "User"; col5.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col5.SetValue(Grid.RowProperty, 0); col5.SetValue(Grid.ColumnProperty, 5); grd_MainGrid.Children.Add(col5); var col6 = new Label(); col6.Content = "Remarks"; col6.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col6.SetValue(Grid.RowProperty, 0); col6.SetValue(Grid.ColumnProperty, 6); grd_MainGrid.Children.Add(col6); var col7 = new Label(); col7.Content = "Status"; col7.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; col7.SetValue(Grid.RowProperty, 0); col7.SetValue(Grid.ColumnProperty, 7); grd_MainGrid.Children.Add(col7); // Fill the process (steps) list in GlobalVars. Routine is actually called when ManageProcess is instantiated. ManageProcess mp = new ManageProcess(); // Flag for logic. bool NoMatch = true; for (int i = 0; i < GlobalVars.sList.Count(); i++) { // Reset flag each time. NoMatch = true; foreach (Task t in GlobalVars.tList) { if (t.i_StepID == GlobalVars.sList[i].i_StepID) { NoMatch = false; // Start new row to load step. var rowDefinition = new RowDefinition(); rowDefinition.Height = GridLength.Auto; grd_MainGrid.RowDefinitions.Add(rowDefinition); // Load "is completed?" checkbox. var chkbox = new CheckBox(); chkbox.IsEnabled = false; if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].i_Status == 0) { chkbox.IsChecked = false; } else if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].i_Status == 1) { chkbox.IsChecked = false; } else { chkbox.IsChecked = true; } chkbox.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); chkbox.SetValue(Grid.ColumnProperty, 0); chkbox.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Center); chkbox.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); grd_MainGrid.Children.Add(chkbox); // Load step number. var stepnum = new Label(); stepnum.Content = GlobalVars.sList[i].i_Order; stepnum.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); stepnum.SetValue(Grid.ColumnProperty, 1); grd_MainGrid.Children.Add(stepnum); // Load title. var title = new Label(); title.Content = GlobalVars.sList[i].Title; if ((GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].ActionDate < DateTime.Today) && (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].i_Status != 2) && (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].ActionDate != default(DateTime))) { title.Foreground = Brushes.Red; title.Content += " (Overdue)"; } title.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); title.SetValue(Grid.ColumnProperty, 2); grd_MainGrid.Children.Add(title); // Load description. var description = new Label(); if (GlobalVars.sList[i].Description.Length > 40) { description.Content = GlobalVars.sList[i].Description.Substring(0, 40) + "..."; description.SetValue(ToolTipProperty, GlobalVars.sList[i].Description); } else { description.Content = GlobalVars.sList[i].Description; } description.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); description.SetValue(Grid.ColumnProperty, 3); grd_MainGrid.Children.Add(description); // Load due date. var date = new Label(); date.Content = GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].ActionDate; date.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); date.SetValue(Grid.ColumnProperty, 4); grd_MainGrid.Children.Add(date); // Load action user. var user = new Label(); user.Content = GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].ActionUser; user.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); user.SetValue(Grid.ColumnProperty, 5); grd_MainGrid.Children.Add(user); //Load remarks. var remarks = new Label(); if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].Remarks != null) { if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].Remarks.Length > 40) { remarks.Content = GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].Remarks.Substring(0, 40) + "..."; remarks.SetValue(ToolTipProperty, GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].Remarks); } else { remarks.Content = GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].Remarks; } } else { remarks.Content = "None"; } remarks.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); remarks.SetValue(Grid.ColumnProperty, 6); grd_MainGrid.Children.Add(remarks); // Load status. var status = new Label(); if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].i_Status == 0) { status.Content = "Not Started"; status.Foreground = Brushes.Red; } else if (GlobalVars.tList[GlobalVars.sList[i].i_Order - 1].i_Status == 1) { status.Content = "In Progress"; status.Foreground = Brushes.Orange; } else { status.Content = "Complete"; status.Foreground = Brushes.Green; } status.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); status.SetValue(Grid.ColumnProperty, 7); grd_MainGrid.Children.Add(status); // Load edit button. var edit = new Button(); edit.Content = "Edit"; edit.Name = "btn_Edit" + GlobalVars.sList[i].i_Order; edit.Width = 45; edit.Height = 20; edit.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); edit.SetValue(Grid.ColumnProperty, 8); edit.Click += edit_Click; grd_MainGrid.Children.Add(edit); } } if (NoMatch == true) { // Start new row to load step. var rowDefinition = new RowDefinition(); rowDefinition.Height = GridLength.Auto; grd_MainGrid.RowDefinitions.Add(rowDefinition); // Load "is completed?" checkbox. var chkbox = new CheckBox(); chkbox.IsEnabled = false; chkbox.IsChecked = false; chkbox.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); chkbox.SetValue(Grid.ColumnProperty, 0); chkbox.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Center); chkbox.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); grd_MainGrid.Children.Add(chkbox); // Load step number. var stepnum = new Label(); stepnum.Content = GlobalVars.sList[i].i_Order; stepnum.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); stepnum.SetValue(Grid.ColumnProperty, 1); grd_MainGrid.Children.Add(stepnum); // Load title. var title = new Label(); title.Content = GlobalVars.sList[i].Title; title.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); title.SetValue(Grid.ColumnProperty, 2); grd_MainGrid.Children.Add(title); // Load description. var description = new Label(); if (GlobalVars.sList[i].Description.Length > 40) { description.Content = GlobalVars.sList[i].Description.Substring(0, 40) + "..."; description.SetValue(ToolTipProperty, GlobalVars.sList[i].Description); } else { description.Content = GlobalVars.sList[i].Description; } description.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); description.SetValue(Grid.ColumnProperty, 3); grd_MainGrid.Children.Add(description); // Load due date. var date = new Label(); date.IsEnabled = false; date.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); date.SetValue(Grid.ColumnProperty, 4); grd_MainGrid.Children.Add(date); // Load action user. var user = new Label(); user.Content = "N/A"; user.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); user.SetValue(Grid.ColumnProperty, 5); grd_MainGrid.Children.Add(user); //Load remarks. var remarks = new Label(); remarks.Content = "N/A"; remarks.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); remarks.SetValue(Grid.ColumnProperty, 6); grd_MainGrid.Children.Add(remarks); // Load status. var status = new Label(); status.Content = "Not Started"; status.Foreground = Brushes.Red; status.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); status.SetValue(Grid.ColumnProperty, 7); grd_MainGrid.Children.Add(status); // Load edit button. var edit = new Button(); edit.Content = "Edit"; edit.Name = "btn_Edit" + GlobalVars.sList[i].i_Order; edit.Width = 40; edit.Height = 20; edit.SetValue(Grid.RowProperty, GlobalVars.sList[i].i_Order); edit.SetValue(Grid.ColumnProperty, 8); edit.Click += edit_Click; grd_MainGrid.Children.Add(edit); } } }