Пример #1
0
 public AdornerUserControl()
 {
     InitializeComponent();
     TextCommand       = new Command.RelayCommand(() => TextBlock1.Text += " New Text");
     Grid1.DataContext = this;
     controlColourer   = new(this);
     //adornerController = new(Square3Grid);
     GearGrid.SetValue(AdornerEx.AdornerProperty, new CustomFrameworkElementAdorner(GearGrid));
     Square3Grid.SetValue(DataContextProperty, new Characters());
     Square3Grid.SetValue(AdornerEx.AdornerProperty, new SettingsAdorner(Square3Grid));
     Square3Grid.SetValue(AdornerEx.IsEnabledProperty, true);
     //Square3Grid.AddIfMissingAdorner(new SettingsControl());
 }
Пример #2
0
 public AdornerUserControl()
 {
     InitializeComponent();
     TextCommand       = new Command.RelayCommand(() => TextBlock1.Text += " New Text");
     Grid1.DataContext = this;
 }
        public MasterDetailView()
        {
            var outputChanges = SelectChanges(nameof(Output)).Where(obj => obj != null);

            //Dictionary<Type, object> dict = new Dictionary<Type, object>();
            outputChanges
            .CombineLatest(SelectChanges <string>(nameof(Id)).StartWith(Id), (a, b) => (a, b))
            .Select(vm =>
            {
                var id = vm.a.GetType().GetProperty(vm.b).GetValue(vm.a).ToString();
                return(id);
            }).Subscribe(NameChanges);

            outputChanges
            .CombineLatest(SelectChanges <IValueConverter>(nameof(DataConverter)).StartWith(default(IValueConverter)), (a, b) => (a, b))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOnDispatcher()
            .Subscribe(collConv => Dispatcher.InvokeAsync(() =>
            {
                Convert(collConv.a, collConv.b, (items, conv) => conv.Convert(collConv.a, null, null, null) as IEnumerable);
            }, DispatcherPriority.Normal));

            SelectChanges <PropertyGroupDescription>().StartWith(PropertyGroupDescription)
            .CombineLatest(ControlChanges.Where(c => c.GetType() == typeof(DockPanel)).Take(1), (pgd, DockPanel) => (pgd, DockPanel)).Subscribe(_ =>
            {
                if ((_.DockPanel as DockPanel)?.FindResource("GroupedItems") is CollectionViewSource collectionViewSource)
                {
                    collectionViewSource.GroupDescriptions.Add(_.pgd);
                }
            });

            GroupClick = new Command.RelayCommand <string>(a => GroupNameChanges.OnNext(a));

            NameChanges
            .Merge(GroupNameChanges)
            .CombineLatest(ControlChanges.Select(c => c as TextBlock).Where(c => c != null),

                           (text, textBlock) => (text, textBlock))
            .ObserveOnDispatcher()
            .Subscribe(input =>
            {
                input.textBlock.Text       = input.text;
                input.textBlock.Visibility = Visibility.Visible;
                input.textBlock.IsEnabled  = true;
                input.textBlock.IsEnabled  = false;
            });

            GroupNameChanges.CombineLatest(
                SelectChanges <PropertyGroupDescription>().StartWith(PropertyGroupDescription),
                SelectChanges <IValueConverter>(nameof(DataConverter)).StartWith(default(IValueConverter)),
                SelectChanges <string>(nameof(Id)).StartWith(Id),
                (text, pg, conv, id) => (text, pg, conv, id))
            //.ObserveOn(TaskPoolScheduler.Default)
            .Subscribe(async input =>
            {
                await Dispatcher.InvokeAsync(() =>
                {
                    var paths = Items.Cast <object>();
                    var prop  = paths.First().GetType().GetProperty(input.pg.PropertyName);

                    // property-group-converter
                    var converter = input.pg.Converter;

                    var group = paths.Where(ad =>
                    {
                        bool result = converter != default ?
                                      input.text
                                      .Equals(converter.Convert(prop.GetValue(ad), null, null, null)) :
                                      input.text
                                      .Equals(prop.GetValue(ad));
                        return(result);
                    })
                                .Select(viewmodel =>
                                        new Property.KeyValue(
                                            viewmodel.GetType().GetProperty(input.id).GetValue(viewmodel).ToString(),
                                            viewmodel));
                    Convert(group, input.conv, (items, conv) => conv.Convert(items, null, null, null));
                }, DispatcherPriority.Background);
            });

            ContentTemplateSelector = new PropertyDataTemplateSelector();
        }