|
сериализация canvas
|
|||
---|---|---|---|
#18+
[Serializable] public class MyVisualHost : Canvas { public List<Visual> children = new List<Visual>(); public MyVisualHost() { } private bool change_figur_position; public Visual active; BindingExpressionBase bb; myline line; DrawingVisual drawline; private Point drawlinepoint; public bool drawlin=false; private string help; public void addpeople(Point p) { people peopl = new people(p); children.Add(peopl); base.AddLogicalChild(peopl); base.AddVisualChild(peopl); } public void removechildren(Visual vis) { this.RemoveVisualChild(vis); this.children.Remove(vis); this.RemoveVisualChild(vis); } public void addline(parent n , parent m) { help += "a"; //n.pp = new Point(n.pp.X-20, n.pp.Y-20); line = new myline(n.pp,m.pp,help); children.Add(line); base.AddLogicalChild(line); base.AddVisualChild(line); line.bind = new Binding("pp"); line.bind.Source =n; line.bind.Mode = BindingMode.TwoWay; bb= BindingOperations.SetBinding(line, line.xxproperty, line.bind); line.bind1 = new Binding("pp"); line.bind1.Source = m; BindingOperations.SetBinding(line, line.xx2property, line.bind1); } public void add_ellipse(Point p) { myellipse visual = new myellipse(p); active = visual; children.Add(visual); base.AddVisualChild(visual); base.AddLogicalChild(visual); } public parent find_figur(Point p) { DependencyObject obj = VisualTreeHelper.HitTest(this, p).VisualHit; if ((obj.GetType().ToString() == "diplom_my.people") || (obj.GetType().ToString() == "diplom_my.myellipse")) return (parent) obj ; return null; } private void moveline(myline line, Point p) { if ((line.p1.X + 6 > p.X) && (line.p1.X - 6 < p.X) && (line.p1.Y + 6 > p.Y) && (line.p1.X - 6 < p.X)) { line.p1 = p; } else if ((line.p2.X + 2 < p.X) && (line.p2.X - 2 > p.X) && (line.p2.Y + 2 < p.Y) && (line.p2.X - 2 > p.Y)) { line.p2 = p; } } protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); if (change_figur_position == true) { change_figur_position = false; active = null; } if (drawlin==true) { children.Remove(drawline); this.RemoveVisualChild(drawline); drawline = null; drawlin = false; if ((find_figur(e.GetPosition(this)) != null) && (find_figur(drawlinepoint) != (find_figur(e.GetPosition(this))))) addline(find_figur(drawlinepoint), find_figur(e.GetPosition(this))); drawlinepoint = new Point(0, 0); } } protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) { base.OnMouseMove(e); if ((drawlin==true) && (drawlinepoint!=new Point(0,0))) { DrawingContext cn = drawline.RenderOpen(); Pen p=new Pen(Brushes.Black,3); cn.DrawLine(p,drawlinepoint,e.GetPosition(this)); cn.Close(); } else { if (change_figur_position == true) { if (active.GetType().ToString() == "diplom_my.people") { ((people)active).pp = e.GetPosition(this); ((people)active).move(e.GetPosition(this)); } if (active.GetType().ToString() == "diplom_my.myellipse") { ((myellipse)active).pp = e.GetPosition(this); ((myellipse)active).move(e.GetPosition(this)); } if (active.GetType().ToString() == "diplom_my.myline") { moveline((myline)active, e.GetPosition(this)); } } } } protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); if (drawlin == true) { if ((find_figur(e.GetPosition(this)) != null) && ((find_figur(e.GetPosition(this))).GetType().ToString() != "diplom_my.myline")) { drawlinepoint = e.GetPosition(this); drawline = new DrawingVisual(); this.AddVisualChild(drawline); children.Add(drawline); } } if (this.find_figur(e.GetPosition(this)) != null) { active = this.find_figur(e.GetPosition(this)); change_figur_position = true; } else change_figur_position = false; } protected override int VisualChildrenCount { get { return children.Count; } } protected override Visual GetVisualChild(int index) { if (index < 0 || index >= children.Count) { throw new ArgumentOutOfRangeException(); } return children[index]; } помогите настроить сериализацию! ... |
|||
:
Нравится:
Не нравится:
|
|||
28.11.2011, 11:56 |
|
сериализация canvas
|
|||
---|---|---|---|
#18+
может тебе сначала помочь, в освоении инструментов написания вопросов? ... |
|||
:
Нравится:
Не нравится:
|
|||
28.11.2011, 12:02 |
|
сериализация canvas
|
|||
---|---|---|---|
#18+
а что непонятного.нужно сериализовать класс.хоть каким нибудь способом. XmlSerializer xml=new XmlSerializer(typeof(MyVisualHost)); using (Stream s = File.OpenWrite(@"D:/AA.xml")) xml.Serialize(s, myVisualHost1); выдаёт ошибку There was an error reflecting type 'ррр.MyVisualHost'. ... |
|||
:
Нравится:
Не нравится:
|
|||
28.11.2011, 12:32 |
|
сериализация canvas
|
|||
---|---|---|---|
#18+
sergei64_89, тебе надо научится смотреть полный текст ошибки. ... |
|||
:
Нравится:
Не нравится:
|
|||
28.11.2011, 12:45 |
|
сериализация canvas
|
|||
---|---|---|---|
#18+
Cannot serialize member System.Windows.Input.InputBinding.Command of type System.Windows.Input.ICommand because it is an interface ... |
|||
:
Нравится:
Не нравится:
|
|||
28.11.2011, 12:53 |
|
|
start [/forum/topic.php?fid=21&msg=37547570&tid=1442048]: |
0ms |
get settings: |
8ms |
get forum list: |
12ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
34ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
44ms |
get tp. blocked users: |
1ms |
others: | 14ms |
total: | 127ms |
0 / 0 |