예제 #1
0
        internal static FrameworkElementFactory CreateBoundCellRenderer(ApplicationContext ctx, WidgetBackend parent, CellView view, string dataPath = ".")
        {
            ICellViewFrontend fr       = view;
            TextCellView      textView = view as TextCellView;

            if (textView != null)
            {
                // if it's an editable textcontrol, use a TextBox, if not use a TextBlock. Reason for this is that
                // a user usually expects to be able to edit a text if a text cursor is appearing above a field.
                FrameworkElementFactory factory;
                if (textView.Editable || textView.EditableField != null)
                {
                    factory = new FrameworkElementFactory(typeof(SWC.TextBox));
                    if (textView.Editable)
                    {
                        factory.SetValue(SWC.TextBox.IsReadOnlyProperty, false);
                    }
                    else
                    {
                        factory.SetBinding(SWC.TextBox.IsEnabledProperty, new Binding(dataPath + "[" + textView.EditableField.Index + "]"));
                    }

                    if (textView.TextField != null)
                    {
                        factory.SetBinding(SWC.TextBox.TextProperty, new Binding(dataPath + "[" + textView.TextField.Index + "]"));
                    }
                    else
                    {
                        factory.SetValue(SWC.TextBox.TextProperty, textView.Text);
                    }
                }
                else
                {
                    factory = new FrameworkElementFactory(typeof(SWC.TextBlock));

                    if (textView.MarkupField != null)
                    {
                        factory.SetBinding(SWC.TextBlock.TextProperty, new Binding(dataPath + "[" + textView.MarkupField.Index + "]")
                        {
                            Converter = new MarkupToPlainTextConverter()
                        });
                    }
                    else if (textView.TextField != null)
                    {
                        factory.SetBinding(SWC.TextBlock.TextProperty, new Binding(dataPath + "[" + textView.TextField.Index + "]"));
                    }
                    else
                    {
                        factory.SetValue(SWC.TextBlock.TextProperty, textView.Text);
                    }
                }

                var cb = new TextCellViewBackend();
                cb.Initialize(view, factory, parent as ICellRendererTarget);
                fr.AttachBackend(parent.Frontend, cb);
                return(factory);
            }

            ImageCellView imageView = view as ImageCellView;

            if (imageView != null)
            {
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ImageBox));

                if (imageView.ImageField != null)
                {
                    var binding = new Binding(dataPath + "[" + imageView.ImageField.Index + "]");
                    binding.Converter = new ImageToImageSourceConverter(ctx);

                    factory.SetBinding(ImageBox.ImageSourceProperty, binding);
                }

                var cb = new CellViewBackend();
                cb.Initialize(view, factory, parent as ICellRendererTarget);
                fr.AttachBackend(parent.Frontend, cb);
                return(factory);
            }

            CanvasCellView canvasView = view as CanvasCellView;

            if (canvasView != null)
            {
                var cb = new CanvasCellViewBackend();
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CanvasCellViewPanel));
                factory.SetValue(CanvasCellViewPanel.CellViewBackendProperty, cb);

                cb.Initialize(view, factory, parent as ICellRendererTarget);
                fr.AttachBackend(parent.Frontend, cb);
                return(factory);
            }

            CheckBoxCellView cellView = view as CheckBoxCellView;

            if (cellView != null)
            {
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(SWC.CheckBox));
                if (cellView.EditableField == null)
                {
                    factory.SetValue(FrameworkElement.IsEnabledProperty, cellView.Editable);
                }
                else
                {
                    factory.SetBinding(SWC.CheckBox.IsEnabledProperty, new Binding(dataPath + "[" + cellView.EditableField.Index + "]"));
                }

                factory.SetValue(SWC.CheckBox.IsThreeStateProperty, cellView.AllowMixed);
                if (cellView.ActiveField != null)
                {
                    factory.SetBinding(SWC.CheckBox.IsCheckedProperty, new Binding(dataPath + "[" + cellView.ActiveField.Index + "]"));
                }

                var cb = new CheckBoxCellViewBackend();
                cb.Initialize(view, factory, parent as ICellRendererTarget);
                fr.AttachBackend(parent.Frontend, cb);
                return(factory);
            }

            throw new NotImplementedException();
        }
예제 #2
0
파일: CellUtil.cs 프로젝트: akrisiun/xwt
        internal static FrameworkElementFactory CreateBoundCellRenderer(ApplicationContext ctx, Widget parent, CellView view, string dataPath = ".")
        {
            ICellViewFrontend fr = view;
            TextCellView textView = view as TextCellView;
            if (textView != null) {
                // if it's an editable textcontrol, use a TextBox, if not use a TextBlock. Reason for this is that
                // a user usually expects to be able to edit a text if a text cursor is appearing above a field.
                FrameworkElementFactory factory;
                if (textView.Editable || textView.EditableField != null)
                {
                    factory = new FrameworkElementFactory(typeof(SWC.TextBox));
                    if (textView.Editable)
                        factory.SetValue(SWC.TextBox.IsReadOnlyProperty, false);
                    else
                        factory.SetBinding(SWC.TextBox.IsEnabledProperty, new Binding(dataPath + "[" + textView.EditableField.Index + "]"));

                    if (textView.TextField != null)
                        factory.SetBinding(SWC.TextBox.TextProperty, new Binding(dataPath + "[" + textView.TextField.Index + "]"));
                    else
                        factory.SetValue(SWC.TextBox.TextProperty, textView.Text);
                }
                else
                {
                    factory = new FrameworkElementFactory(typeof(SWC.TextBlock));

                    if (textView.MarkupField != null)
                        factory.SetBinding(SWC.TextBlock.TextProperty, new Binding(dataPath + "[" + textView.MarkupField.Index + "]") { Converter = new MarkupToPlainTextConverter () });
                    else if (textView.TextField != null)
                        factory.SetBinding(SWC.TextBlock.TextProperty, new Binding(dataPath + "[" + textView.TextField.Index + "]"));
                    else
                        factory.SetValue(SWC.TextBlock.TextProperty, textView.Text);
                }

                var cb = new CellViewBackend();
                cb.Initialize(view, factory);
                fr.AttachBackend(parent, cb);
                return factory;
            }

            ImageCellView imageView = view as ImageCellView;
            if (imageView != null) {
                FrameworkElementFactory factory = new FrameworkElementFactory (typeof (ImageBox));

                if (imageView.ImageField != null) {
                    var binding = new Binding (dataPath + "[" + imageView.ImageField.Index + "]");
                    binding.Converter = new ImageToImageSourceConverter (ctx);

                    factory.SetBinding (ImageBox.ImageSourceProperty, binding);
                }

                var cb = new CellViewBackend();
                cb.Initialize(view, factory);
                fr.AttachBackend(parent, cb);
                return factory;
            }

            CanvasCellView canvasView = view as CanvasCellView;
            if (canvasView != null)
            {
                var cb = new CanvasCellViewBackend();
                FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CanvasCellViewPanel));
                factory.SetValue(CanvasCellViewPanel.CellViewBackendProperty, cb);

                cb.Initialize(view, factory);
                fr.AttachBackend(parent, cb);
                return factory;
            }

            CheckBoxCellView cellView = view as CheckBoxCellView;
            if (cellView != null) {
                FrameworkElementFactory factory = new FrameworkElementFactory (typeof(SWC.CheckBox));
                if (cellView.EditableField == null)
                    factory.SetValue (FrameworkElement.IsEnabledProperty, cellView.Editable);
                else
                    factory.SetBinding (SWC.CheckBox.IsEnabledProperty, new Binding (dataPath + "[" + cellView.EditableField.Index + "]"));

                factory.SetValue (SWC.CheckBox.IsThreeStateProperty, cellView.AllowMixed);
                if (cellView.ActiveField != null)
                    factory.SetBinding (SWC.CheckBox.IsCheckedProperty, new Binding (dataPath + "[" + cellView.ActiveField.Index + "]"));

                var cb = new CellViewBackend ();
                cb.Initialize (view, factory);
                fr.AttachBackend (parent, cb);
                return factory;
            }

            throw new NotImplementedException ();
        }