/// <summary> /// Makes the list picker. /// </summary> /// <param name="setting">The setting.</param> /// <returns>ListPicker.</returns> private static ListPicker MakeListPicker(Setting setting) { var lpValue = new ListPicker { Header = String.Format((string)"{0}", (object)setting.FriendlyName.Trim()) }; var items = Enumerable.ToList <string>(setting.StringItem.Select(item => item.Value)); lpValue.ItemsSource = items; lpValue.SetBinding(ListPicker.SelectedItemProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = setting }); return(lpValue); }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { // Because a form can have its data-context (= workitem data that is linked to it) changed multiple times, we set a flag after the first execution to prevent our code from firing more than once. if (flag == false) { // Find the tab-control of our form (it is important when adding our custom usercontrol in the MP XML to use a parent that is in the general tabcontrol) DependencyObject doTabControl = GetParentDependancyObject(this, "Microsoft.EnterpriseManagement.ServiceManager.Applications.ProblemManagement.Forms.GeneralTabControl"); GeneralTabControl tabitem_general = (GeneralTabControl)doTabControl; // Get the existing assigned-to field, and get its parent container, which is a stackpanel. A stackpanel adds controls right after another, so is ideal for adding extra controls without worrying too much about layout. UserPicker userPicker = (UserPicker)tabitem_general.FindName("AssignedToUserPicker"); System.Windows.Controls.StackPanel parent = (System.Windows.Controls.StackPanel)userPicker.Parent; // Define the extra controls and bind them to the data lp = new ListPicker(new Guid("e24ffbc7-78fd-a2da-e4b1-32312a8035ce")); myBinding = new Binding(); myBinding.Source = this.DataContext as IDataItem; myBinding.Path = new PropertyPath("SupportGroup"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; lp.Name = "SupportGroupListPicker"; lp.Width = Double.NaN; // AUTO lp.Height = Double.NaN; // AUTO lp.HorizontalAlignment = HorizontalAlignment.Stretch; lp.VerticalAlignment = VerticalAlignment.Center; Label lbl = new Label(); lbl.HorizontalAlignment = HorizontalAlignment.Left; lbl.VerticalAlignment = VerticalAlignment.Center; lbl.Content = "Support Group:"; // Add the controls to the stackpanel parent.Children.Add(lbl); parent.Children.Add(lp); flag = true; } // Update the binding when data is changed else { myBinding = new Binding(); myBinding.Source = this.DataContext as IDataItem; myBinding.Path = new PropertyPath("SupportGroup"); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; lp.SetBinding(ListPicker.SelectedItemProperty, myBinding); } }
/// <summary> /// Makes the contact chooser. /// </summary> /// <param name="setting">The setting.</param> /// <param name="p">The p.</param> private void MakeContactChooser(Setting setting, out StackPanel p) { try { p = new StackPanel { Orientation = Orientation.Vertical }; TextBlock tbFriendlyName = MakeCaption(setting); if (string.IsNullOrEmpty(setting.ContactDisplayName)) { setting.ContactDisplayName = "Choose Contact"; } var bButton = new HyperlinkButton { HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(-5, 0, 0, 0) }; bButton.SetBinding(ContentControl.ContentProperty, new Binding("ContactDisplayName") { Mode = BindingMode.TwoWay, Source = setting }); bButton.Click += bButton_Click; p.Children.Add(tbFriendlyName); p.Children.Add(bButton); var tbCc = new TextBox { Name = String.Format((string)"txt{0}", (object)setting.Name.Replace(" ", String.Empty)), Height = 72, MaxLength = 50, TextWrapping = TextWrapping.NoWrap }; tbCc.SetBinding(TextBox.TextProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = setting }); tbCc.InputScope = new InputScope { Names = { new InputScopeName { NameValue = (setting.AddressType == addressType.Email ? InputScopeNameValue.EmailNameOrAddress : InputScopeNameValue.TelephoneNumber) } } }; var lbAddressType = new ListPicker { Header = "DEFAULT SEND TYPE" }; IEnumerable <FieldInfo> fields = (typeof(addressType)).GetFields().Skip(1); lbAddressType.ItemsSource = from field in fields select field.Name; lbAddressType.SetBinding(ListPicker.SelectedItemProperty, new Binding("AddressType") { Converter = new EnumValueConverter(), Mode = BindingMode.TwoWay, Source = setting }); p.Children.Add(tbCc); p.Children.Add(lbAddressType); } catch (Exception e) { p = null; } }
private void CreateValueEditor(ComboBox box) { var presenter = GetValuePresenterForCombo(box); presenter.Content = null; presenter.HorizontalAlignment = HorizontalAlignment.Stretch; if (box.SelectedItem != null) { var pd = (PropertyDefinition)box.SelectedItem; if (pd.PropertyType == PropertyDefinitionType.EnumDisplayName || pd.PropertyType == PropertyDefinitionType.EnumName || pd.PropertyType == PropertyDefinitionType.Property) { Binding b = new Binding(pd.Property.Name); b.Source = this.DataContext; b.Mode = BindingMode.TwoWay; if (pd.PropertyType == PropertyDefinitionType.Property) { if (pd.Property.Type == ManagementPackEntityPropertyTypes.datetime) { var dp = new DatePicker() { MinWidth = 200, SelectedDateFormat = DatePickerFormat.FullDateTime }; dp.SetBinding(DatePicker.SelectedDateProperty, b); presenter.Content = dp; } else if (pd.Property.Type == ManagementPackEntityPropertyTypes.@bool) { var cb = new CheckBox() { Content = pd.Property.Name }; cb.SetBinding(CheckBox.IsCheckedProperty, b); presenter.Content = cb; } else { var txt = new TextBox() { Text = "test", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch, MinWidth = 200 }; txt.SetBinding(TextBox.TextProperty, b); presenter.Content = txt; } } else { var lp = new ListPicker(); lp.ParentCategoryId = pd.Property.EnumType.Id; lp.SetBinding(ListPicker.SelectedItemProperty, b); presenter.Content = lp; } } } }