Пример #1
0
        /// <summary>
        /// 根据给定的表单信息和回调消息构建一个表单窗口
        /// </summary>
        /// <param name="formInfo">表单项的信息</param>
        /// <param name="callbackMsg">回调消息</param>
        public static void ShowWindow(List <FormStruct> formInfo, AllAppMsg callbackMsg)
        {
            DialogueWindowViewModel vm     = new DialogueWindowViewModel(formInfo, callbackMsg);
            DialogueWindow          window = new DialogueWindow();

            window.DataContext = vm;
            window.Show();
        }
        void LoadContent()
        {
            DialogueWindowViewModel VM = DataContext as DialogueWindowViewModel;

            foreach (FormStruct formItem in VM.FormStructs)
            {
                switch (formItem.type)
                {
                case FormItemType.InputLine:
                    InputLine tmpInputLine = new InputLine();
                    tmpInputLine.Margin         = new Thickness(0, 0, 0, 20);
                    tmpInputLine.InputAreaWidth = 400;
                    tmpInputLine.InputName      = formItem.name;
                    VM.CallBackValues.Add("Value", "");
                    BindingOperations.SetBinding(tmpInputLine, InputLine.InputTextProperty, new Binding()
                    {
                        Path = new PropertyPath("CallBackValues[Value]"),
                        Mode = BindingMode.TwoWay
                    });
                    MainPanel.Children.Add(tmpInputLine);
                    break;

                case FormItemType.InputText:
                    break;

                case FormItemType.DropDown:
                    DropDown tmpDropDown = new DropDown();
                    tmpDropDown.Margin         = new Thickness(0, 0, 0, 20);
                    tmpDropDown.InputAreaWidth = 400;
                    tmpDropDown.InputName      = formItem.name;
                    tmpDropDown.InputList      = formItem.parameters as List <string>;
                    VM.CallBackValues.Add("Value", tmpDropDown.InputList[0]);
                    BindingOperations.SetBinding(tmpDropDown, DropDown.SelectedItemProperty, new Binding()
                    {
                        Path = new PropertyPath("CallBackValues[Value]"),
                        Mode = BindingMode.TwoWay
                    });
                    MainPanel.Children.Add(tmpDropDown);
                    break;

                case FormItemType.InputDropDown:
                    InputDropDown tmpInputDropDown = new InputDropDown();
                    tmpInputDropDown.Margin         = new Thickness(0, 0, 0, 20);
                    tmpInputDropDown.InputAreaWidth = 400;
                    tmpInputDropDown.InputName      = formItem.name;
                    tmpInputDropDown.InputList      = formItem.parameters as List <string>;
                    VM.CallBackValues.Add("Value", "");
                    BindingOperations.SetBinding(tmpInputDropDown, InputDropDown.EffectiveValueProperty, new Binding()
                    {
                        Path = new PropertyPath("CallBackValues[Value]"),
                        Mode = BindingMode.TwoWay
                    });
                    MainPanel.Children.Add(tmpInputDropDown);
                    break;
                }
            }

            Button button = new Button();

            BindingOperations.SetBinding(button, Button.CommandProperty, new Binding()
            {
                Path = new PropertyPath("CallbackCommand"),
            });
            button.Content = "确定";
            button.Click  += (sender, e) => { this.Close(); };
            MainPanel.Children.Add(button);
        }