예제 #1
0
        private void PrepareLookupWindow()
        {
            lookupWindow = new LookupWindow();
            lookupWindow.maingrid.FlowDirection    = FlowDirection;
            lookupWindow.title.Text                = WindowTitle;
            lookupWindow.searchpanel.SearchCommand = SearchCommand;
            lookupWindow.searchpanel.RowMargin     = 5;
            lookupWindow.searchpanel.ColumnMargin  = 10;
            lookupWindow.LookupMode                = LookupWindow.LookupModeEnum.Grid;

            var bind = new Binding("ItemsSource")
            {
                Source = this
            };

            BindingOperations.SetBinding(lookupWindow, DataContextProperty, bind);
            lookupWindow.SelectionMode         = SelectionMode;
            lookupWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            var sourceType = ItemsSource?.GetType();

            if (sourceType != null)
            {
                if (sourceType.IsGenericType)
                {
                    lookupWindow.searchpanel.ModelType = sourceType.GenericTypeArguments[0];
                }
            }

            if (SearchFields != null)
            {
                foreach (var item in SearchFields)
                {
                    item.Clear();
                    lookupWindow.searchpanel.SearchFields.Add(item);
                }
            }

            lookupWindow.datagrid.ColumnsToAdd = Columns;

            if (SelectionMode == LookupSelectionMode.Single)
            {
                var buttonColumn = new CustomButtonColumn();
                buttonColumn.Image          = new BitmapImage(new Uri("/Infra.Wpf;component/Controls/Resources/Select-24.png", UriKind.RelativeOrAbsolute));
                buttonColumn.MouseOverImage = new BitmapImage(new Uri("/Infra.Wpf;component/Controls/Resources/SelectOver-24.png", UriKind.RelativeOrAbsolute));
                buttonColumn.Width          = new C1.WPF.DataGrid.DataGridLength(32);
                buttonColumn.Order          = 0;
                buttonColumn.Command        = SelectCommand;
                lookupWindow.datagrid.ButtonColumns.Add(buttonColumn);
            }
            else
            {
                var checkColumn = new CustomCheckBoxColumn();
                checkColumn.IsSelectable = true;
                checkColumn.Binding      = new Binding("IsSelected");
                checkColumn.Width        = new C1.WPF.DataGrid.DataGridLength(32);
                lookupWindow.datagrid.Columns.Add(checkColumn);
            }
        }
예제 #2
0
        private void PrepareLookupWindow()
        {
            treeLookupWindow = new LookupWindow();
            treeLookupWindow.maingrid.FlowDirection    = FlowDirection;
            treeLookupWindow.title.Text                = WindowTitle;
            treeLookupWindow.searchpanel.SearchCommand = SearchCommand;
            treeLookupWindow.searchpanel.RowMargin     = 5;
            treeLookupWindow.searchpanel.ColumnMargin  = 10;
            treeLookupWindow.LookupMode                = LookupWindow.LookupModeEnum.Tree;

            treeLookupWindow.SelectionMode         = SelectionMode;
            treeLookupWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            var sourceType = FlatItemsSource?.GetType();

            if (sourceType != null)
            {
                if (sourceType.IsGenericType)
                {
                    treeLookupWindow.searchpanel.ModelType = sourceType.GenericTypeArguments[0];
                }
            }

            if (SearchFields != null)
            {
                foreach (var item in SearchFields)
                {
                    item.Clear();
                    treeLookupWindow.searchpanel.SearchFields.Add(item);
                }
            }

            if (HierarchicalData != null)
            {
                ResourceDictionary resource = new ResourceDictionary();
                foreach (var item in HierarchicalData)
                {
                    resource.Add(new DataTemplateKey(item.DataType), CreateHierarchicalDataTemplate(item));
                }

                treeLookupWindow.treeview.Resources = resource;
            }

            var bind = new Binding("ItemsSource")
            {
                Source = this
            };

            BindingOperations.SetBinding(treeLookupWindow, DataContextProperty, bind);

            if (SelectionMode == LookupSelectionMode.Multi && typeof(ISelectable).IsAssignableFrom(ResultType))
            {
                foreach (var item in FlatItemsSource.Cast <ISelectable>())
                {
                    item.IsSelected = false;
                }
            }
        }