Git Product home page Git Product logo

Comments (5)

BillShawn avatar BillShawn commented on June 3, 2024

well, issue 3 is closed now;

from wpfdesigner.

BillShawn avatar BillShawn commented on June 3, 2024

a new issue, ComboBoxEditor can not work. change ComboBoxEditor.xaml content
`<ComboBox
x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.ComboBoxEditor"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
BorderThickness="1"
SelectedValue="{Binding DesignerValue}"
Background="Transparent"
Focusable="False"
Margin="0"
VirtualizingStackPanel.ScrollUnit="Pixel"
VirtualizingStackPanel.IsVirtualizing="True"
ScrollViewer.CanContentScroll="True"

`
now ,it work

from wpfdesigner.

jogibear9988 avatar jogibear9988 commented on June 3, 2024

Could you create pull requests with fixes for your issues?
I've no time to look for the at the moment

from wpfdesigner.

BillShawn avatar BillShawn commented on June 3, 2024

issue1: DataGrid can not edit colunms with its right top contextmenu
change code in QuickOperationMenuExtension.cs
method OnMenuLoaded and MainHeaderClick
`private void OnMenuLoaded(object sender, EventArgs e)
{
if(_menu.MainHeader!=null)
_menu.MainHeader.Click += MainHeaderClick;

		int menuItemsAdded = 0;
		var view = this.ExtendedItem.View;

		if (view != null) {
			string setValue;
			if(view is ItemsControl) {
				if (view is DataGrid )
				{
					_menu.AddSubMenuInTheHeader(new MenuItem() { Header = "Edit DataGrid Columns" });
				}
				else
				{
					_menu.AddSubMenuInTheHeader(new MenuItem() { Header = "Edit Items" });
				}
				
			}
			
			if(view is Grid) {
				_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Rows"});
				_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Columns"});
			}
			
			if (view is StackPanel) {
				var ch = new MenuItem() {Header = "Change Orientation"};
				_menu.AddSubMenuInTheHeader(ch);
				setValue = this.ExtendedItem.Properties[StackPanel.OrientationProperty].ValueOnInstance.ToString();
				_menu.AddSubMenuCheckable(ch, Enum.GetValues(typeof (Orientation)), Orientation.Vertical.ToString(), setValue);
				_menu.MainHeader.Items.Add(new Separator());
				menuItemsAdded++;
			}
			
			if(this.ExtendedItem.Parent!=null && this.ExtendedItem.Parent.View is DockPanel) {
				var sda = new MenuItem() {Header = "Set Dock to"};
				_menu.AddSubMenuInTheHeader(sda);
				setValue = this.ExtendedItem.Properties.GetAttachedProperty(DockPanel.DockProperty).ValueOnInstance.ToString();
				_menu.AddSubMenuCheckable(sda, Enum.GetValues(typeof (Dock)), Dock.Left.ToString(), setValue);
				_menu.MainHeader.Items.Add(new Separator());
				menuItemsAdded++;
			}

			var ha = new MenuItem() {Header = "Horizontal Alignment"};
			_menu.AddSubMenuInTheHeader(ha);
			setValue = this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance.ToString();
			_menu.AddSubMenuCheckable(ha, Enum.GetValues(typeof (HorizontalAlignment)), HorizontalAlignment.Stretch.ToString(), setValue);
			menuItemsAdded++;

			var va = new MenuItem() {Header = "Vertical Alignment"};
			_menu.AddSubMenuInTheHeader(va);
			setValue = this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance.ToString();
			_menu.AddSubMenuCheckable(va, Enum.GetValues(typeof (VerticalAlignment)), VerticalAlignment.Stretch.ToString(), setValue);
			menuItemsAdded++;
			
			if (!(this.ExtendedItem.Parent?.Component is Panel)|| this.ExtendedItem.Parent?.Component is Grid)
			{
				_menu.AddSubMenuInTheHeader(new MenuItem() { Header = "Set Fill" });
			}
			
		}

		if (menuItemsAdded == 0) {
			OnRemove();
		}
	}

	private void MainHeaderClick(object sender, RoutedEventArgs e)
	{
		var clickedOn = e.Source as MenuItem;
		if (clickedOn != null) {
			var parent = clickedOn.Parent as MenuItem;
			if (parent != null) {
				
				if((string)clickedOn.Header=="Edit Items") {
					var editor = new CollectionEditor();
					var itemsControl=this.ExtendedItem.View as ItemsControl;
					if (itemsControl != null)
						editor.LoadItemsCollection(this.ExtendedItem);
					editor.Show();
				}

				if ((string)clickedOn.Header == "Edit DataGrid Columns")
				{
					var editor = new FlatCollectionEditor();
					var itemsControl = this.ExtendedItem.View as DataGrid;
					if (itemsControl != null)
						editor.LoadItemsCollection(this.ExtendedItem.Properties["Columns"]);
					editor.Show();
				}

				if ((string)clickedOn.Header=="Edit Rows") {
					var editor = new FlatCollectionEditor();
					var gd=this.ExtendedItem.View as Grid;
					if (gd != null)
						editor.LoadItemsCollection(this.ExtendedItem.Properties["RowDefinitions"]);
					editor.Show();
				}
				
				if((string)clickedOn.Header=="Edit Columns") {
					var editor = new FlatCollectionEditor();
					var gd=this.ExtendedItem.View as Grid;
					if (gd != null)
						editor.LoadItemsCollection(this.ExtendedItem.Properties["ColumnDefinitions"]);
					editor.Show();
				}
				
				if (parent.Header is string && (string) parent.Header == "Change Orientation") {
					var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
					if (value != null) {
						var orientation = Enum.Parse(typeof (Orientation), value);
						if (orientation != null)
							this.ExtendedItem.Properties[StackPanel.OrientationProperty].SetValue(orientation);
					}
				}
				if (parent.Header is string && (string)parent.Header == "Set Dock to") {
					var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
					if(value!=null) {
						var dock = Enum.Parse(typeof (Dock), value);
						if (dock != null)
							this.ExtendedItem.Properties.GetAttachedProperty(DockPanel.DockProperty).SetValue(dock);
					}
				}
				

				if (parent.Header is string && (string) parent.Header == "Horizontal Alignment") {
					var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
					if (value != null) {
						var ha = Enum.Parse(typeof (HorizontalAlignment), value);
						if (ha != null)
							this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha);
					}
				}

				if (parent.Header is string && (string) parent.Header == "Vertical Alignment") {
					var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
					if (value != null) {
						var va = Enum.Parse(typeof (VerticalAlignment), value);
						if (va != null)
							this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va);
					}
				}

				if ((string)clickedOn.Header == "Set Fill")
				{

					this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Stretch);
					this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Stretch);

					this.ExtendedItem.Properties[FrameworkElement.WidthProperty].SetValue(double.NaN);
					this.ExtendedItem.Properties[FrameworkElement.HeightProperty].SetValue(double.NaN);
					this.ExtendedItem.Properties[FrameworkElement.MarginProperty].SetValue(new Thickness(3));
				}
			}
		}
	}

you can call a FlatCollectionEditor after click Edit Columns menu,but it can not work , we must change FlatCollectionEditor.xaml.cs// Copyright (c) 2019 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Linq;
using ICSharpCode.WpfDesign.Designer.themes;
using System.Collections.ObjectModel;

namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
{
public partial class FlatCollectionEditor : Window
{
private static readonly Dictionary<Type, Type[]> TypeMappings = new Dictionary<Type, Type[]>();
static FlatCollectionEditor()
{
TypeMappings.Add(typeof(ListBox),new Type[] { typeof(ListBoxItem) });
TypeMappings.Add(typeof(ListView), new Type[] { typeof(ListViewItem) });
TypeMappings.Add(typeof(ComboBox), new Type[] { typeof(ComboBoxItem) });
TypeMappings.Add(typeof(TabControl), new Type[] { typeof(TabItem) });
TypeMappings.Add(typeof(ColumnDefinitionCollection), new Type[] { typeof(ColumnDefinition) });
TypeMappings.Add(typeof(RowDefinitionCollection), new Type[] { typeof(RowDefinition) });
TypeMappings.Add(typeof(ObservableCollection), new Type[] { typeof(DataGridTextColumn), typeof(DataGridComboBoxColumn), typeof(DataGridCheckBoxColumn) });
}

	private DesignItemProperty _itemProperty;
	private IComponentService _componentService;
	//private Type _type;
	
	public FlatCollectionEditor()
	{
		SpecialInitializeComponent();
		
		//this.Owner = Application.Current.MainWindow;
	}
	
	/// <summary>
	/// Fixes InitializeComponent with multiple Versions of same Assembly loaded
	/// </summary>
	public void SpecialInitializeComponent()
	{
		if (!this._contentLoaded) {
			this._contentLoaded = true;
			Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
			Application.LoadComponent(this, resourceLocator);
		}
		
		this.InitializeComponent();
	}
	
	public Type GetItemsSourceType(Type t)
	{
		Type tp = t.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));

		return (tp != null ) ? tp.GetGenericArguments()[0] : null;
	}
	
	public void LoadItemsCollection(DesignItemProperty itemProperty)
	{
		_itemProperty = itemProperty;
		_componentService=_itemProperty.DesignItem.Services.Component;
		TypeMappings.TryGetValue(_itemProperty.ReturnType, out Type[] _type);
		
		_type = _type ?? new Type[] { GetItemsSourceType(_itemProperty.ReturnType) };
		
		if (_type == null) {
			AddItem.IsEnabled=false;
		}

		cbx_Type.ItemsSource = _type;
		if (_type.Length>0)
		{
			cbx_Type.SelectedIndex = 0;
		}
		ListBox.ItemsSource = _itemProperty.CollectionElements;
	}
	
	private void OnAddItemClicked(object sender, RoutedEventArgs e)
	{
		if (cbx_Type.SelectedItem is Type _type)
		{
			DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));
			_itemProperty.CollectionElements.Add(newItem);
		}
	}

	private void OnRemoveItemClicked(object sender, RoutedEventArgs e)
	{
		var selItem = ListBox.SelectedItem as DesignItem;
		if (selItem != null)
			_itemProperty.CollectionElements.Remove(selItem);
	}
	
	private void OnMoveItemUpClicked(object sender, RoutedEventArgs e)
	{
		DesignItem selectedItem = ListBox.SelectedItem as DesignItem;
		if (selectedItem!=null) {
			if(_itemProperty.CollectionElements.Count!=1 && _itemProperty.CollectionElements.IndexOf(selectedItem)!=0){
				int moveToIndex=_itemProperty.CollectionElements.IndexOf(selectedItem)-1;
				var itemAtMoveToIndex=_itemProperty.CollectionElements[moveToIndex];
				_itemProperty.CollectionElements.RemoveAt(moveToIndex);
				if ((moveToIndex + 1) < (_itemProperty.CollectionElements.Count+1))
					_itemProperty.CollectionElements.Insert(moveToIndex+1,itemAtMoveToIndex);
			}
		}
	}

	private void OnMoveItemDownClicked(object sender, RoutedEventArgs e)
	{
		DesignItem selectedItem = ListBox.SelectedItem as DesignItem;
		if (selectedItem!=null) {
			var itemCount=_itemProperty.CollectionElements.Count;
			if(itemCount!=1 && _itemProperty.CollectionElements.IndexOf(selectedItem)!=itemCount){
				int moveToIndex=_itemProperty.CollectionElements.IndexOf(selectedItem)+1;
				if(moveToIndex<itemCount){
					var itemAtMoveToIndex=_itemProperty.CollectionElements[moveToIndex];
					_itemProperty.CollectionElements.RemoveAt(moveToIndex);
					if(moveToIndex>0)
						_itemProperty.CollectionElements.Insert(moveToIndex-1,itemAtMoveToIndex);
				}
			}
		}
	}
	
	void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
	{
		PropertyGridView.PropertyGrid.SelectedItems = ListBox.SelectedItems.Cast<DesignItem>();
		e.Handled = true;
	}
}

}
`

from wpfdesigner.

BillShawn avatar BillShawn commented on June 3, 2024

Iuess 2 and 3,cancel drag control to TabControl and DataGrid
Line15 -Line154,source code is :
if (ExtendedItem.ContentProperty.IsCollection) return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType, operation.PlacedItems.Select(p => p.Item.Component));
change it
`

if (ExtendedItem.ContentProperty.IsCollection)
{
if (ExtendedItem.Component is Panel)
return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType,
operation.PlacedItems.Select(p => p.Item.Component));
return false;
}

`

from wpfdesigner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.