예제 #1
0
        protected virtual FrameworkElement CreateCommandLinkControl(PropertyItem property)
        {
            var commandAtt = property.Descriptor.Attributes.OfType <Attribute>().FirstOrDefault(att => att is IPrefabCommand) as IPrefabCommand;


            var c = new CommandLinkBlock {
                PrefabInvocation = commandAtt, VerticalAlignment = VerticalAlignment.Center, TextDecorations = TextDecorations.Underline
            };

            if (property.GetAttribute <AssignCommandDataAttribute>() != null)
            {
                c.CommandDataAssignment = true;
            }


            c.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(property.Descriptor.Name));
            c.SetBinding(CommandLinkBlock.CommandProperty, property.CreateBinding());

            if (c.CommandDataAssignment)
            {
                c.SetBinding(CommandLinkBlock.CommandDataProperty,
                             new System.Windows.Data.Binding("SelectedObject")
                {
                    RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(PropertyControlEx), 1), Mode = BindingMode.OneWay
                });
            }

            return(c);
        }
        protected virtual FrameworkElement CreateCommandLinkControl(PropertyDefinition d, int index)
        {
            var commandAtt =
                d.Descriptor.Attributes.OfType <Attribute>().FirstOrDefault(att => att is IPrefabCommand) as IPrefabCommand;

            var cl = new CommandLinkBlock
            {
                PrefabInvocation    = commandAtt,
                HorizontalAlignment = d.HorizontalAlignment,
                VerticalAlignment   = VerticalAlignment.Center,
                Padding             = new Thickness(4, 0, 4, 0),
                TextDecorations     = TextDecorations.Underline,
            };

            if (d.Descriptor.Attributes.OfType <AssignCommandDataAttribute>().Any())
            {
                cl.CommandDataAssignment = true;
            }


            cl.SetBinding(TextBlock.TextProperty, new Binding(d.Descriptor.Name));
            cl.SetBinding(CommandLinkBlock.CommandProperty, d.CreateOneWayBinding(index));

            if (cl.CommandDataAssignment)
            {
                cl.SetBinding(CommandLinkBlock.CommandDataProperty, new Binding("SelectedItems")
                {
                    RelativeSource =
                        new RelativeSource(
                            RelativeSourceMode.FindAncestor,
                            typeof(ItemsGrid), 1),
                    Mode = BindingMode.OneWay
                });
            }

            return(cl);
        }