I'm trying to Copy and Paste part of my list. Unfortunately, when pasting from the clipboard, the condition finds the stored data, but when assigned to the variable it is still equal to null. This is my code for List and List Item.
public class ListCanvasBlocks : List<MyBlock>
{
public List<MyBlock> MyCopySelectedObj()
{
var x = new List<MyBlock>();
x.AddRange(this.Where(z => z.IsSelected));
return x;
}
}
[Serializable]
public class MyBlock
{
public MyBlock(Rectangle rect, BlocksData.Shape shape,int id)
{
Rect = rect;
Shape = shape;
Text = BlocksData.Text(Shape);
ID = id;
}
public string Text;
public bool IsSelected { get; set; } = false;
public bool IsLocked = false;
public int ID{ get; set; }
public Point PointInput;
public Point PointOutput1, PointOutput2;
public Rectangle Rect;
public SolidBrush BackColor;
public Color FontColor;
public int FontSize;
public BlocksData.Shape Shape{get;set;}
}
and this is what i do when i press ctrl+c/v
public void Copy()
{
Clipboard.Clear();
Clipboard.SetData("ListCanvasBlocks", _canvObj.MyCopySelectedObj());
}
public void Paste()
{
if (Clipboard.ContainsData("ListCanvasBlocks"))
{var test = (ListCanvasBlocks)Clipboard.GetData("ListCanvasBlocks");}
}
Condition in Paste method return true but variable test is still null after assigment
BlockData.Shape is enum
At the moment when I tried to individually add variables to the clipboard, it turned out that the problem was serialization
. The problem was solved in SolodBrush
because its attribute is Color
, and only variables without attributes can be serialized.
There i found solution when i found what is real problem