Exemple #1
0
 private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     CToggleBtn temp = d as CToggleBtn;
 }
Exemple #2
0
        public static Control CreateCell(object a, object b, int Row, int Column)
        {
            Control Good = null;

            if (a is DeviceModel && b is DeviceModel)
            {
                DeviceModel A = a as DeviceModel;
                DeviceModel B = b as DeviceModel;
                Good = new CToggleBtn()
                {
                };
                Good.ToolTip = string.Format(A.DeviceName + "&&" + B.DeviceName);
            }
            else if (a is DeviceModel && b is DeviceInterface)
            {
                DeviceModel     A = a as DeviceModel;
                DeviceInterface B = b as DeviceInterface;
                Good = new CLabel()
                {
                    IsCommon = false
                };
                Good.ToolTip = string.Format(A.DeviceName);
            }
            else if (a is DeviceInterface && b is DeviceModel)
            {
                DeviceInterface A = a as DeviceInterface;
                DeviceModel     B = b as DeviceModel;
                Good = new CLabel()
                {
                    IsCommon = false
                };
                Good.ToolTip = string.Format(B.DeviceName);
            }
            else if (a is DeviceInterface && b is DeviceInterface)
            {
                DeviceInterface A = a as DeviceInterface;
                DeviceInterface B = b as DeviceInterface;
                Good = new CLabel()
                {
                    IsCommon = true
                };
                Good.ToolTip = string.Format(A.InterfaceName + "=>" + B.InterfaceName);
            }
            if (Good == null)
            {
                return(Good);
            }
            Binding B1 = new Binding("RowState")
            {
                Source = ViewModel.cellsState[Row][Column]
            };
            Binding B2 = new Binding("ColumnState")
            {
                Source = ViewModel.cellsState[Row][Column]
            };

            MultiBinding MBinding = new MultiBinding()
            {
                Mode = BindingMode.OneWay
            };

            MBinding.Bindings.Add(B1);
            MBinding.Bindings.Add(B2);
            if (Good is CToggleBtn)
            {
                MBinding.Converter = Converter.CellStateConverter;
                Good.SetBinding(CToggleBtn.ChangedIconProperty, MBinding);
            }
            else
            {
                MBinding.Converter = Converter.CellVisibilityConverter;
                Good.SetBinding(CLabel.VisibilityProperty, MBinding);
            }
            return((Control)Good);
        }
        private void CGridItemsSource_ExtendedItemsChanged(object item, bool AddOrRemove)
        {
            if (!(item is DeviceModel))
            {
                return;
            }
            if (AddOrRemove)
            {
                DeviceModel device = item as DeviceModel;
                InnerDeviceList.Add(device);
                ConstructionHelper.Add(device);
                foreach (DeviceInterface element in device.InterfaceList)
                {
                    ConstructionHelper.Add(element);
                }
                foreach (List <CellState> RowList in ViewModel.cellsState)
                {
                    for (int i = 0; i < device.InterfaceCount + 1; i++)
                    {
                        RowList.Add(new Model.CellState()
                        {
                            RowState = false, ColumnState = false
                        });
                    }
                }
                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    RowCreateHelper.Add(new Model.CellState()
                    {
                        RowState = false, ColumnState = false
                    });
                }
                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    ViewModel.cellsState.Add(new List <Model.CellState>(RowCreateHelper));
                }
                foreach (List <CellState> RowList in ViewModel.cellsState)
                {
                    foreach (var e in RowList)
                    {
                        Debug.Write("1--");
                    }
                    Debug.Write("\n");
                }

                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    this.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(0, GridUnitType.Auto)
                    });
                    this.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(0, GridUnitType.Auto)
                    });
                }

                foreach (List <Control> RowList in CellsControl)
                {
                    int RowIndex = CellsControl.IndexOf(RowList);
                    for (int i = 0; i < device.InterfaceCount + 1; i++)
                    {
                        if (ConstructionHelper[RowIndex] is DeviceModel)
                        {
                            DeviceModel TempDev = ConstructionHelper[RowIndex] as DeviceModel;
                            if (i == 0)
                            {
                                CToggleBtn TempBtn = new CToggleBtn()
                                {
                                };
                                TempBtn.ToolTip = string.Format(TempDev.DeviceName + "&&" + device.DeviceName);

                                int ColumnIndex = ConstructionHelper.IndexOf(device);
                                Grid.SetColumn(TempBtn, ColumnIndex);
                                Grid.SetRow(TempBtn, RowIndex);
                                Binding B1 = new Binding("RowState")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };
                                Binding B2 = new Binding("Column")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };

                                MultiBinding MBinding = new MultiBinding()
                                {
                                    Mode = BindingMode.OneWay
                                };
                                MBinding.Bindings.Add(B1);
                                MBinding.Bindings.Add(B2);
                                MBinding.Converter = Converter.CellStateConverter;

                                TempBtn.SetBinding(CToggleBtn.ChangedIconProperty, MBinding);
                            }
                            else
                            {
                                CLabel TempCLabel = new CLabel()
                                {
                                    IsCommon = false
                                };
                                TempCLabel.ToolTip = string.Format(TempDev.DeviceName);
                                int ColumnIndex = ConstructionHelper.IndexOf(device.InterfaceList[i - 1]);
                                Grid.SetColumn(TempCLabel, ColumnIndex);
                                Grid.SetRow(TempCLabel, RowIndex);

                                Binding B1 = new Binding("RowState")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };
                                Binding B2 = new Binding("Column")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };

                                MultiBinding MBinding = new MultiBinding()
                                {
                                    Mode = BindingMode.OneWay
                                };
                                MBinding.Bindings.Add(B1);
                                MBinding.Bindings.Add(B2);
                                MBinding.Converter = Converter.CellStateConverter;
                                TempCLabel.SetBinding(CLabel.IsSelectedProperty, MBinding);
                            }
                        }
                        else
                        {
                            DeviceInterface TempInterface = ConstructionHelper[RowIndex] as DeviceInterface;
                            if (i == 0)
                            {
                                CLabel TempCLabel = new CLabel()
                                {
                                    IsCommon = false
                                };
                                TempCLabel.ToolTip = string.Format(device.DeviceName);
                                int ColumnIndex = ConstructionHelper.IndexOf(device);

                                Grid.SetColumn(TempCLabel, ColumnIndex);
                                Grid.SetRow(TempCLabel, RowIndex);

                                Binding B1 = new Binding("RowState")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };
                                Binding B2 = new Binding("Column")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };

                                MultiBinding MBinding = new MultiBinding()
                                {
                                    Mode = BindingMode.OneWay
                                };
                                MBinding.Bindings.Add(B1);
                                MBinding.Bindings.Add(B2);
                                MBinding.Converter = Converter.CellStateConverter;

                                TempCLabel.SetBinding(CToggleBtn.ChangedIconProperty, MBinding);
                            }
                            else
                            {
                                CLabel TempCLabel = new CLabel()
                                {
                                    IsCommon = true
                                };
                                TempCLabel.ToolTip = string.Format(TempInterface.InterfaceName + "=>" + device.InterfaceList[i - 1].InterfaceName);
                                int ColumnIndex = ConstructionHelper.IndexOf(device.InterfaceList[i - 1]);
                                Grid.SetColumn(TempCLabel, ColumnIndex);
                                Grid.SetRow(TempCLabel, RowIndex);
                                Binding B1 = new Binding("RowState")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };
                                Binding B2 = new Binding("Column")
                                {
                                    Source = cellsState[RowIndex][ColumnIndex]
                                };

                                MultiBinding MBinding = new MultiBinding()
                                {
                                    Mode = BindingMode.OneWay
                                };
                                MBinding.Bindings.Add(B1);
                                MBinding.Bindings.Add(B2);
                                MBinding.Converter = Converter.CellStateConverter;
                                TempCLabel.SetBinding(CLabel.IsSelectedProperty, MBinding);
                            }
                        }
                    }
                }

                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    if (i == 0)
                    {
                        foreach (var e in ConstructionHelper)
                        {
                            CToggleBtn TempBtn = new CToggleBtn()
                            {
                            };
                        }
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                DeviceModel device      = item as DeviceModel;
                int         Index       = InnerDeviceList.IndexOf(device);
                int         RemoveIndex = ConstructionHelper.IndexOf(device);
                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    ViewModel.cellsState.RemoveAt(RemoveIndex);
                }
                foreach (List <CellState> RowList in ViewModel.cellsState)
                {
                    for (int i = 0; i < device.InterfaceCount + 1; i++)
                    {
                        RowList.RemoveAt(RemoveIndex);
                    }
                }
                for (int i = 0; i < device.InterfaceCount + 1; i++)
                {
                    ConstructionHelper.RemoveAt(RemoveIndex);
                    RowCreateHelper.RemoveAt(RemoveIndex);
                }
                InnerDeviceList.Remove((DeviceModel)item);
                foreach (List <CellState> RowList in ViewModel.cellsState)
                {
                    foreach (var e in RowList)
                    {
                        Debug.Write("1--");
                    }
                    Debug.Write("\n");
                }
            }
        }