コード例 #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TreeViewModel)
            {
                TreeViewModel tvm = (TreeViewModel)value;

                if (tvm.IsRoot)
                {
                    Uri         uri    = new Uri("pack://application:,,,/green.png");
                    BitmapImage source = new BitmapImage(uri);
                    return(source);
                }
                else
                {
                    Uri         uri    = new Uri("pack://application:,,,/blue.png");
                    BitmapImage source = new BitmapImage(uri);
                    return(source);
                }
            }
            return(null);
        }
コード例 #2
0
        public static List <TreeViewModel> SetTree(string topLevelName)
        {
            List <TreeViewModel> treeView = new List <TreeViewModel>();
            TreeViewModel        tv       = new TreeViewModel(topLevelName);

            tv.IsNodeExpanded = true;
            tv.IsRoot         = true;

            treeView.Add(tv);

            //Perform recursive method to build treeview

            #region Test Data
            //Doing this below for this example, you should do it dynamically
            //***************************************************
            TreeViewModel tvChild4 = new TreeViewModel("Child4");
            tvChild4.IsRoot = true;

            tv.Children.Add(new TreeViewModel("Child1"));
            tv.Children.Add(new TreeViewModel("Child2"));
            tv.Children.Add(new TreeViewModel("Child3"));
            tv.Children.Add(tvChild4);
            tv.Children.Add(new TreeViewModel("Child5"));

            TreeViewModel grtGrdChild2 = (new TreeViewModel("GrandChild4-2"));
            grtGrdChild2.IsRoot = true;

            tvChild4.Children.Add(new TreeViewModel("GrandChild4-1"));
            tvChild4.Children.Add(grtGrdChild2);
            tvChild4.Children.Add(new TreeViewModel("GrandChild4-3"));

            grtGrdChild2.Children.Add(new TreeViewModel("GreatGrandChild4-2-1"));
            //***************************************************
            #endregion

            tv.Initialize();

            return(treeView);
        }
コード例 #3
0
        public static List <TreeViewModel> SetTree(string topLevelName, List <UASFNC> funtionCodeList)
        {
            List <TreeViewModel> treeView = new List <TreeViewModel>();

            TreeViewModel selectAll = new TreeViewModel(topLevelName);

            treeView.Add(selectAll);

            TreeViewModel tvm_system      = new TreeViewModel("System");
            TreeViewModel tvm_operation   = new TreeViewModel("Operation");
            TreeViewModel tvm_maintenance = new TreeViewModel("Maintenance");
            TreeViewModel tvm_debug       = new TreeViewModel("Debug");

            tvm_system.Name      = "System";
            tvm_operation.Name   = "Operation";
            tvm_maintenance.Name = "Maintenance";
            tvm_debug.Name       = "Debug";

            selectAll.Children.Add(tvm_system);
            selectAll.Children.Add(tvm_operation);
            selectAll.Children.Add(tvm_maintenance);
            selectAll.Children.Add(tvm_debug);


            //Perform recursive method to build treeview

            foreach (UASFNC functionCode in funtionCodeList)
            {
                TreeViewModel a;
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.System_Function.FUNC_LOGIN)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_system.Children.Add(a);
                    //a.Name = BCAppConstants.System_Function.FUNC_LOGIN;
                    a.Name = "Login System";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.System_Function.FUNC_ACCOUNT_MANAGEMENT)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_system.Children.Add(a);
                    //a.Name = BCAppConstants.System_Function.FUNC_ACCOUNT_MANAGEMENT;
                    a.Name = "Account Management";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.System_Function.FUNC_CLOSE_SYSTEM)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_system.Children.Add(a);
                    //a.Name = BCAppConstants.System_Function.FUNC_CLOSE_SYSTEM;
                    a.Name = "Exit System";
                }

                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Operation_Function.FUNC_SYSTEM_CONCROL_MODE)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_operation.Children.Add(a);
                    //a.Name = BCAppConstants.Operation_Function.FUNC_SYSTEM_CONCROL_MODE;
                    a.Name = "System Mode Control";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Operation_Function.FUNC_TRANSFER_MANAGEMENT)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_operation.Children.Add(a);
                    //a.Name = BCAppConstants.Operation_Function.FUNC_TRANSFER_MANAGEMENT;
                    a.Name = "Transfer Management";
                }

                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Maintenance_Function.FUNC_ADVANCED_SETTINGS)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_maintenance.Children.Add(a);
                    //a.Name = BCAppConstants.Maintenance_Function.FUNC_MTS_MTL_MAINTENANCE;
                    a.Name = "Advanced Settings";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Maintenance_Function.FUNC_MTS_MTL_MAINTENANCE)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_maintenance.Children.Add(a);
                    //a.Name = BCAppConstants.Maintenance_Function.FUNC_MTS_MTL_MAINTENANCE;
                    a.Name = "MTL/MTS Maintenance";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Maintenance_Function.FUNC_PORT_MAINTENANCE)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_maintenance.Children.Add(a);
                    //a.Name = BCAppConstants.Maintenance_Function.FUNC_PORT_MAINTENANCE;
                    a.Name = "Port Maintenance";
                }
                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Maintenance_Function.FUNC_VEHICLE_MANAGEMENT)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_maintenance.Children.Add(a);
                    //a.Name = BCAppConstants.Operation_Function.FUNC_VEHICLE_MANAGEMENT;
                    a.Name = "Vehicle Management";
                }

                if (functionCode.FUNC_CODE.Trim() == BCAppConstants.Debug_Function.FUNC_DEBUG)
                {
                    a = new TreeViewModel(functionCode.FUNC_CODE.ToString());
                    tvm_debug.Children.Add(a);
                    //a.Name = BCAppConstants.Debug_Function.FUNC_DEBUG;
                    a.Name = "Debug(Used during testing)";
                }
            }

            //#region Test Data
            ////Doing this below for this example, you should do it dynamically
            ////***************************************************
            //TreeViewModel t1 = new TreeViewModel("System");
            //tv.Children.Add(t1);
            //t1.Children.Add(new TreeViewModel("Account Management"));
            //t1.Children.Add(new TreeViewModel("Exit System"));

            //TreeViewModel t2 = new TreeViewModel("Operation");
            //tv.Children.Add(t2);
            //t2.Children.Add(new TreeViewModel("System Mode Control"));
            //t2.Children.Add(new TreeViewModel("Transfer Management"));

            //TreeViewModel t3 = new TreeViewModel("Maintenance");
            //tv.Children.Add(t3);
            //t3.Children.Add(new TreeViewModel("Port Maintenance"));
            //t3.Children.Add(new TreeViewModel("Vehicle Management"));
            ////***************************************************
            //#endregion

            selectAll.Initialize();

            return(treeView);
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     treeView1.ItemsSource = TreeViewModel.SetTree("Top Level");
 }