コード例 #1
0
        public CatalogOfferView()
        {
            InitializeComponent();
            var grid = Offers;

            grid.CommandBindings.Add(new CommandBinding(DataGrid.DeleteCommand,
                                                        Commands.DoInvokeViewModel,
                                                        Commands.CanInvokeViewModel));

            Conventions.ConfigureDataGrid(grid, typeof(Offer));
            new Editable().Attach(grid);
            DataGridHelper.CalculateColumnWidths(Offers);
            ApplyStyles();
            BindingOperations.SetBinding(OfferOverlayPanel, Grid.MaxHeightProperty,
                                         new Binding("ActualHeight")
            {
                Source    = Offers,
                Converter = new LambdaConverter <double>(v => v * 0.7)
            });

            var element = Rounding;
            var items   = DescriptionHelper.GetDescriptions(typeof(Rounding));

            element.ItemsSource       = items;
            element.DisplayMemberPath = "Name";

            var binding = new Binding("Rounding.Value")
            {
                Converter          = new ComboBoxSelectedItemConverter(),
                ConverterParameter = items
            };

            BindingOperations.SetBinding(element, Selector.SelectedItemProperty, binding);
        }
コード例 #2
0
        public WaybillDetailsView()
        {
            InitializeComponent();
            DataContextChanged += OnDataContextChanged;

            var element = Rounding;
            var items   = DescriptionHelper.GetDescriptions(typeof(Rounding));

            element.ItemsSource       = items;
            element.DisplayMemberPath = "Name";

            var binding = new Binding("Waybill.Rounding");

            binding.Converter          = new ComboBoxSelectedItemConverter();
            binding.ConverterParameter = items;
            BindingOperations.SetBinding(element, Selector.SelectedItemProperty, binding);

            DataContextChanged += (sender, args) => {
                if (model == null)
                {
                    return;
                }
                var handler = new BarcodeHandler(this, model.Settings);
                handler.Barcode.Subscribe(x => Execute(model.BarcodeScanned(x)));
            };
        }
コード例 #3
0
        protected override void OnViewAttached(object view, object context)
        {
            base.OnViewAttached(view, context);

            var grid = (Grid)((FrameworkElement)view).FindName("Data");

            grid.DataContext = Target;
            for (var i = 0; i < Properties.Length; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition());
                var property = Properties[i];
                var label    = new Label {
                    Content = ((DisplayAttribute)property.Item2[0]).Name
                };
                label.SetValue(Grid.RowProperty, i);
                label.SetValue(Grid.ColumnProperty, 0);
                grid.Children.Add(label);

                UIElement          input;
                DependencyProperty inputProperty = null;
                var propertyType = property.Item1.PropertyType;
                if (propertyType == typeof(DateTime))
                {
                    input         = new DatePicker();
                    inputProperty = DatePicker.SelectedDateProperty;
                }
                else if (propertyType.IsEnum)
                {
                    input = new ComboBox();
                    var items = DescriptionHelper.GetDescriptions(propertyType);
                    input.SetValue(ItemsControl.DisplayMemberPathProperty, "Name");
                    input.SetValue(ItemsControl.ItemsSourceProperty, items);

                    var binding = new Binding(property.Item1.Name);
                    binding.Converter          = new ComboBoxSelectedItemConverter();
                    binding.ConverterParameter = items;
                    BindingOperations.SetBinding(input, Selector.SelectedItemProperty, binding);
                }
                else
                {
                    input = new TextBox {
                        MinWidth          = 100,
                        VerticalAlignment = VerticalAlignment.Center
                    };
                    inputProperty = TextBox.TextProperty;
                }
                if (inputProperty != null)
                {
                    BindingOperations.SetBinding(input, inputProperty, new Binding(property.Item1.Name));
                }
                input.SetValue(Grid.RowProperty, i);
                input.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(input);
            }
        }
コード例 #4
0
ファイル: Stocks.cs プロジェクト: molokovskikh/af_analitf-net
        public Stocks()
        {
            DisplayName            = "Товарные запасы";
            AddressSelector        = new AddressSelector(this);
            Items.PropertyChanged += Items_PropertyChanged;
            ItemsTotal             = new ObservableCollection <StockTotal>();
            ItemsTotal.Add(new StockTotal {
                Total = "Итого",
            });

            Name = User?.FullName ?? "";
            StatusFilter.Value = DescriptionHelper.GetDescriptions(typeof(StockStatus))
                                 .Select(x => new Selectable <StockStatus>((StockStatus)x.Value, x.Name))
                                 .ToList();
            QuickSearch = new QuickSearch <Stock>(UiScheduler,
                                                  t => Items?.Value.FirstOrDefault(p => p.Product.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) >= 0),
                                                  CurrentItem);
            TrackDb(typeof(Stock));

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
            CurrentItem.Select(x => x?.WaybillId != null).Subscribe(CanOpenWaybill);
        }
コード例 #5
0
        public static void Register()
        {
            ConventionManager.ApplyValueConverter = ApplyValueConverter;
            ConventionManager.AddElementConvention <SplitButton>(ContentControl.ContentProperty, "DataContext", "Click");
            ConventionManager.AddElementConvention <Run>(Run.TextProperty, "Text", "DataContextChanged");
            ConventionManager.AddElementConvention <IntegerUpDown>(UpDownBase <int?> .ValueProperty, "Value", "ValueChanged");
            ConventionManager.AddElementConvention <FlowDocumentScrollViewer>(FlowDocumentScrollViewer.DocumentProperty, "Document ", "DataContextChanged");
            ConventionManager.AddElementConvention <DocumentViewerBase>(DocumentViewerBase.DocumentProperty, "Document ", "DataContextChanged");
            ConventionManager.AddElementConvention <PasswordBox>(ContentElementBinder.PasswordProperty, "Password", "PasswordChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) => {
                //по умолчанию для PasswordBox установлен шрифт times new roman
                //высота поля ввода вычисляется на основе шрифта
                //если расположить TextBox и PasswordBox на одном уровне то разница в высоте будет заметна
                //правим эту кривизну
                ((PasswordBox)element).FontFamily = SystemFonts.MessageFontFamily;
                return(ConventionManager.SetBindingWithoutBindingOverwrite(viewModelType, path, property, element, convention, convention.GetBindableProperty(element)));
            };

            ConventionManager.AddElementConvention <MultiSelector>(ItemsControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention)
                            => TryBindSelectedItems(viewModelType, path, property, element, convention,
                                                    ((MultiSelector)element).SelectedItems);

            ConventionManager.AddElementConvention <ListBox>(ItemsControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention)
                            => TryBindSelectedItems(viewModelType, path, property, element, convention,
                                                    ((ListBox)element).SelectedItems);

            ConventionManager.AddElementConvention <ComboBox>(ItemsControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) => {
                NotifyValueSupport.Patch(ref path, ref property);
                if (property.PropertyType.IsEnum)
                {
                    if (NotBindedAndNull(element, ItemsControl.ItemsSourceProperty) &&
                        !ConventionManager.HasBinding(element, Selector.SelectedItemProperty))
                    {
                        var items = DescriptionHelper.GetDescriptions(property.PropertyType);
                        element.SetValue(ItemsControl.DisplayMemberPathProperty, "Name");
                        element.SetValue(ItemsControl.ItemsSourceProperty, items);

                        var binding = new Binding(path);
                        binding.Converter          = new ComboBoxSelectedItemConverter();
                        binding.ConverterParameter = items;
                        BindingOperations.SetBinding(element, Selector.SelectedItemProperty, binding);
                    }
                }
                else
                {
                    var fallback = ConventionManager.GetElementConvention(typeof(Selector));
                    if (fallback != null)
                    {
                        return(fallback.ApplyBinding(viewModelType, path, property, element, fallback));
                    }
                }
                return(true);
            };
            ConventionManager.AddElementConvention <DataGrid>(ItemsControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) => {
                var dataGrid = (DataGrid)element;
                if (dataGrid.Columns.Count > 1)
                {
                    Interaction.GetBehaviors(element).Add(new CustomMenu());
                }

                var fallback = ConventionManager.GetElementConvention(typeof(MultiSelector));
                if (fallback != null)
                {
                    var actualProperty = property;
                    var result         = fallback.ApplyBinding(viewModelType, path, actualProperty, element, fallback);
                    var dummy          = "";
                    NotifyValueSupport.Patch(ref dummy, ref actualProperty);
                    var propertyType = actualProperty.PropertyType;
                    if (result &&
                        propertyType.IsGenericType &&
                        typeof(IEnumerable).IsAssignableFrom(propertyType))
                    {
                        ConfigureDataGrid(dataGrid, propertyType.GetGenericArguments()[0]);
                    }
                    return(result);
                }
                return(false);
            };
            ConventionManager.AddElementConvention <Label>(ContentControl.ContentProperty, "Content", "DataContextChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) => {
                return(ConventionManager.SetBindingWithoutBindingOverwrite(viewModelType, path, property, element, convention, convention.GetBindableProperty(element)));
            };
        }