made new ModalStateDefinition class (will be used in OrderBookToolBar)
This commit is contained in:
1 parent
a934021a5a
commit
a1053cc41e
2 files changed
+55
-2
No files matched your search
@@ -7,9 +7,11 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -116,6 +118,56 @@ namespace mbts.ui {
|
||||
}
|
||||
}
|
||||
|
||||
class ModalStateDefinition : StateDefinition {
|
||||
StateDefinition _source;
|
||||
|
||||
static ModalStateDefinition() {
|
||||
StateProperty.OverrideMetadata(typeof(ModalStateDefinition), new PropertyMetadata(
|
||||
StateProperty.DefaultMetadata.DefaultValue,
|
||||
StateProperty.DefaultMetadata.PropertyChangedCallback,
|
||||
coerce_state));
|
||||
|
||||
object coerce_state(DependencyObject d, object base_value) {
|
||||
var sb = new StringBuilder();
|
||||
if (d is ModalStateDefinition msd) {
|
||||
sb.Append(msd.Mode?.ToString());
|
||||
sb.Append(msd.Source?.State);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#region Mode
|
||||
public static readonly DependencyProperty ModeProperty =
|
||||
WPFHelper.create_dp<object, ModalStateDefinition>(nameof(Mode), new PropertyMetadata(null, OnModeChanged));
|
||||
|
||||
static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => d.CoerceValue(StateProperty);
|
||||
|
||||
public object Mode {
|
||||
get => GetValue(ModeProperty);
|
||||
set => SetValue(ModeProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public StateDefinition Source {
|
||||
get => _source;
|
||||
set {
|
||||
if (_source == value) return;
|
||||
if (_source != null)
|
||||
_source.StateChanged -= _on_source_state_changed;
|
||||
_source = value;
|
||||
if (_source != null) {
|
||||
BindingOperations.SetBinding(_source, GroupProperty, new Binding(nameof(Group)) { Source = this, Mode = BindingMode.OneWay });
|
||||
_source.StateChanged += _on_source_state_changed;
|
||||
}
|
||||
CoerceValue(StateProperty);
|
||||
}
|
||||
}
|
||||
|
||||
void _on_source_state_changed(string oldval, string newval) =>
|
||||
CoerceValue(StateProperty);
|
||||
}
|
||||
|
||||
[ContentProperty(nameof(StateDefinitions))]
|
||||
class StateGroupsManager : DependencyObject {
|
||||
IDisposable _state_definitions_hook;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using bts.utils;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -45,6 +43,9 @@ namespace mbts.ui {
|
||||
public static DependencyProperty create_dp<TValue, TOwner>(string name, FrameworkPropertyMetadataOptions options, PropertyChangedCallback<TValue, TOwner> callback, TValue default_value = default) =>
|
||||
DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(default_value, options, prop_changed_callback(callback)));
|
||||
|
||||
public static DependencyProperty create_dp<TValue, TOwner>(string name, PropertyMetadata metadata) =>
|
||||
DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
|
||||
|
||||
public static DependencyPropertyKey create_ro_dp<TValue, TOwner>(string name, TValue default_value = default) =>
|
||||
DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(default_value));
|
||||
|
||||
|
||||
Reference in new issue
Block a user