define FlatTabControl style (will be used in new settings dialogs)
This commit is contained in:
1 parent
e69dc78969
commit
a97a1bd775
5 files changed
+361
-32
No files matched your search
@@ -5,13 +5,17 @@
|
||||
xmlns:ui="clr-namespace:mbts.ui"
|
||||
>
|
||||
<!--Control Base Colors-->
|
||||
<Color x:Key="Control.SuperLightGrayColor">#F6F6F6</Color>
|
||||
<Color x:Key="Control.LightGrayColor">#E5E5E5</Color>
|
||||
<Color x:Key="Control.LightMediumGrayColor">#CFCFCF</Color>
|
||||
<Color x:Key="Control.MediumGrayColor">#B3B3B3</Color>
|
||||
<Color x:Key="Control.MediumDarkGrayColor">#ACACAC</Color>
|
||||
<Color x:Key="Control.AlphaLightGrayColor">#10000000</Color>
|
||||
<Color x:Key="Control.AlphaLightMediumGrayColor">#24000000</Color>
|
||||
<Color x:Key="Control.AlphaMediumGrayColor">#3A000000</Color>
|
||||
<Color x:Key="Control.AlphaMediumGrayColor2">#FF0000</Color>
|
||||
<Color x:Key="Control.DarkMediumGrayColor">#FF959595</Color>
|
||||
<Color x:Key="Control.DarkGrayColor">#707070</Color>
|
||||
<Color x:Key="Text.Prompt.Foreground.Color">#FF999999</Color>
|
||||
|
||||
<SolidColorBrush x:Key="Control.AlphaLightGrayBrush" Color="{StaticResource Control.AlphaLightGrayColor}"/>
|
||||
@@ -140,4 +144,4 @@
|
||||
<SolidColorBrush x:Key="ListBoxItem.Selected.Inactive.Border" Color="{StaticResource ListBoxItem.Selected.Inactive.Border.Color}"/>
|
||||
<SolidColorBrush x:Key="ListBoxItem.MouseOver.Background" Color="{StaticResource ListBoxItem.MouseOver.Background.Color}"/>
|
||||
<SolidColorBrush x:Key="ListBoxItem.MouseOver.Border" Color="{StaticResource ListBoxItem.MouseOver.Border.Color}"/>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -1,10 +1,12 @@
|
||||
using mbts.utils;
|
||||
using bts;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using CompositeDisposable = System.Reactive.Disposables.CompositeDisposable;
|
||||
|
||||
namespace mbts.ui.extensions {
|
||||
@@ -81,6 +83,33 @@ namespace mbts.ui.extensions {
|
||||
}
|
||||
}
|
||||
|
||||
public static IObservable<bool> ObserveIsSelected(this TabItem tab_item) {
|
||||
int subscription_count = 0;
|
||||
BindingProxy proxy = null;
|
||||
return Observable.Create<bool>(o => {
|
||||
if (subscription_count++ == 0) {
|
||||
Log.assert(proxy == null, "Potential memory leak detected: binding proxy should be null when there are 0 subscriptions.");
|
||||
proxy = new BindingProxy();
|
||||
proxy.SetBinding(BindingProxy.ValueProperty, new Binding(nameof(TabItem.IsSelected)) { Source = tab_item });
|
||||
}
|
||||
bool last_observed = tab_item.IsSelected;
|
||||
o.OnNext(last_observed);
|
||||
proxy.ValueChanged += on_value_changed;
|
||||
return Disposable.CreateDisposeOnce(dispose);
|
||||
void dispose() {
|
||||
proxy.ValueChanged -= on_value_changed;
|
||||
if (--subscription_count == 0) {
|
||||
Log.assert(proxy != null, "Binding proxy should not be null when subscriptions are active.");
|
||||
proxy = null;
|
||||
}
|
||||
}
|
||||
void on_value_changed(object d, DependencyPropertyChangedEventArgs e) {
|
||||
if ((e.NewValue is bool b && b) != last_observed)
|
||||
o.OnNext(last_observed = !last_observed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static IObservable<bool> ObserveIsChecked(this ToggleButton toggle_button) =>
|
||||
Observable.Create<bool>(o => {
|
||||
toggle_button.Checked += on_checked;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:controls="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
>
|
||||
<SolidColorBrush x:Key="StartMenuMouseOverBorderBrush" Color="#FFFFB700" />
|
||||
<SolidColorBrush x:Key="StartMenuMouseOverBackground" Color="#6ddbff" />
|
||||
@@ -606,7 +607,7 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border
|
||||
<Border
|
||||
x:Name="Border"
|
||||
CornerRadius="0"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
@@ -635,7 +636,7 @@
|
||||
<Setter TargetName="Border" Property="Background" Value="{mbts:BTSColor UI.Button.pressed_background}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.pressed_border}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocused" Value="true">
|
||||
<Trigger Property="IsKeyboardFocused" Value="true">
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.focused_border}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
@@ -1061,4 +1062,255 @@
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="CenteredTextTemplate">
|
||||
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="FlatTabItemBase" TargetType="TabItem" BasedOn="{StaticResource LargeMenuControlBase}">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="Transparent"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
<Setter Property="Width" Value="{x:Static sys:Double.NaN}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="TabItem">
|
||||
<Border
|
||||
x:Name="Border"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Height="{TemplateBinding Height}"
|
||||
Width="{TemplateBinding Width}"
|
||||
Margin="{TemplateBinding Margin}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
>
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager AttachToMembers="True">
|
||||
<u:StateDefinitionCollection>
|
||||
<u:MouseStateDefinition Mode="Header" MouseSource="{Binding Group.Target, RelativeSource={RelativeSource Self}}"/>
|
||||
<u:SelectedStateDefinition
|
||||
Mode="{Binding Group.Target.TemplatedParent.Parent.TabStripPlacement, RelativeSource={RelativeSource Self}}"
|
||||
Source="{Binding Group.Target.TemplatedParent, RelativeSource={RelativeSource Self}}"
|
||||
/>
|
||||
<u:StateDefinition
|
||||
State="{Binding Group.Target.TemplatedParent.Parent.TabStripPlacement, RelativeSource={RelativeSource Self}, Converter={cv:AppendTextConverter Prefix=Dock}}"
|
||||
/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="HeaderMouseStates">
|
||||
<VisualState Name="HeaderNormal"/>
|
||||
<VisualState Name="HeaderMouseOver">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{u:FrozenBrush {StaticResource Control.AlphaLightMediumGrayColor}}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{u:FrozenBrush {StaticResource Control.DarkGrayColor}}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="TopSelectionStates">
|
||||
<VisualState Name="TopSelected">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="BorderThickness" BeginTime="0" Duration="0" To="1,1,1,0"/>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Padding" BeginTime="0" Duration="0" To="2,4,2,6"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="TopUnselected"/>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="RightSelectionStates">
|
||||
<VisualState Name="RightSelected">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="BorderThickness" BeginTime="0" Duration="0" To="0,1,1,1"/>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Padding" BeginTime="0" Duration="0" To="6,2,4,2"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="RightUnselected"/>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="DockStates">
|
||||
<VisualState Name="DockLeft">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="0,0,0,-1"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="DockTop">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="-1,0,0,0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="DockRight">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="0,0,0,-1"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="DockBottom">
|
||||
<Storyboard>
|
||||
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="-1,0,0,0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<ContentPresenter
|
||||
Name="presenter"
|
||||
Grid.Column="1"
|
||||
ContentSource="Header"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
RecognizesAccessKey="True"
|
||||
/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="FlatTabItem" TargetType="TabItem" BasedOn="{StaticResource FlatTabItemBase}">
|
||||
<Setter Property="MinWidth" Value="60"/>
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource CenteredTextTemplate}"/>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="FlatTabControlTemplate" TargetType="TabControl">
|
||||
<Grid KeyboardNavigation.TabNavigation="Local">
|
||||
<u:StateManager.VisualState>
|
||||
<Binding Path="TabStripPlacement" RelativeSource="{RelativeSource AncestorType=TabControl}">
|
||||
<Binding.Converter>
|
||||
<cv:AppendTextConverter Prefix="TabStrip"/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</u:StateManager.VisualState>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="TabStripPlacementStates">
|
||||
<VisualState Name="TabStripLeft">
|
||||
<Storyboard>
|
||||
<!--Tab Strip-->
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="Margin" BeginTime="0" Duration="0" To="0,4,-1,0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="HorizontalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static HorizontalAlignment.Right}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="VerticalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static VerticalAlignment.Top}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--Content-->
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="1"/>
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="2"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="TabStripTop">
|
||||
<Storyboard>
|
||||
<!--Tab Strip-->
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.Row)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.RowSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="Margin" BeginTime="0" Duration="0" To="4,0,0,-1"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="HorizontalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static HorizontalAlignment.Left}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="VerticalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static VerticalAlignment.Bottom}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--Content-->
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.Row)" BeginTime="0" Duration="0" To="1"/>
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.RowSpan)" BeginTime="0" Duration="0" To="2"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="TabStripRight">
|
||||
<Storyboard>
|
||||
<!--Tab Strip-->
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="2"/>
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="Margin" BeginTime="0" Duration="0" To="-1,4,0,0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="HorizontalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static HorizontalAlignment.Left}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="VerticalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static VerticalAlignment.Top}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--Content-->
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.Column)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="2"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="TabStripBottom">
|
||||
<Storyboard>
|
||||
<!--Tab Strip-->
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.Row)" BeginTime="0" Duration="0" To="1"/>
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.RowSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<Int32Animation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="2"/>
|
||||
<ThicknessAnimation Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="Margin" BeginTime="0" Duration="0" To="4,-1,0,0"/>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="HorizontalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static HorizontalAlignment.Left}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderPanel" Storyboard.TargetProperty="VerticalAlignment">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static VerticalAlignment.Top}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<!--Content-->
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.Row)" BeginTime="0" Duration="0" To="0"/>
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.RowSpan)" BeginTime="0" Duration="0" To="1"/>
|
||||
<Int32Animation Storyboard.TargetName="PART_SelectedContentBorder" Storyboard.TargetProperty="(Grid.ColumnSpan)" BeginTime="0" Duration="0" To="2"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TabPanel
|
||||
x:Name="HeaderPanel"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
Grid.ColumnSpan="3"
|
||||
Panel.ZIndex="1"
|
||||
KeyboardNavigation.TabIndex="1"
|
||||
Background="{u:Brush {StaticResource Control.SuperLightGrayColor}}"
|
||||
IsItemsHost="True"
|
||||
/>
|
||||
<Border
|
||||
x:Name="PART_SelectedContentBorder"
|
||||
Grid.Row="1"
|
||||
Grid.RowSpan="3"
|
||||
Grid.ColumnSpan="3"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
KeyboardNavigation.TabNavigation="Local"
|
||||
KeyboardNavigation.DirectionalNavigation="Contained"
|
||||
KeyboardNavigation.TabIndex="2"
|
||||
>
|
||||
<ContentPresenter
|
||||
x:Name="PART_SelectedContentHost"
|
||||
ContentSource="SelectedContent"
|
||||
/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style x:Key="FlatTabControl" TargetType="TabControl">
|
||||
<Setter Property="Background" Value="{u:Brush}"/>
|
||||
<Setter Property="BorderBrush" Value="{u:Brush {StaticResource Control.MediumDarkGrayColor}}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource FlatTabItem}"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="TabStripPlacement" Value="Top"/>
|
||||
<Setter Property="Template" Value="{StaticResource FlatTabControlTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -3,7 +3,12 @@
|
||||
namespace mbts.ui {
|
||||
class BindingProxy : FrameworkElement {
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.Register(nameof(Value), typeof(object), typeof(BindingProxy));
|
||||
DependencyProperty.Register(nameof(Value), typeof(object), typeof(BindingProxy), new PropertyMetadata(OnValueChanged));
|
||||
|
||||
static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||
((BindingProxy)d).ValueChanged?.Invoke(d, e);
|
||||
|
||||
public event DependencyPropertyChangedEventHandler ValueChanged;
|
||||
|
||||
public object Value {
|
||||
get => GetValue(ValueProperty);
|
||||
|
||||
@@ -115,26 +115,26 @@ namespace mbts.ui {
|
||||
}
|
||||
}
|
||||
|
||||
class CheckedStateDefinition : StateDefinition {
|
||||
class BooleanStateDefinition : StateDefinition {
|
||||
public static readonly Func<FrameworkElement, FrameworkElement> FindMenuItemAncestor =
|
||||
target => target?.find_ancestor_of_type<MenuItem>();
|
||||
|
||||
IDisposable _checkable_source_hook;
|
||||
bool _is_checked;
|
||||
IDisposable _source_hook;
|
||||
bool _value;
|
||||
|
||||
static CheckedStateDefinition() {
|
||||
StateProperty.OverrideMetadata(typeof(CheckedStateDefinition), StateProperty.DefaultMetadata.with(coerce_state));
|
||||
static BooleanStateDefinition() {
|
||||
StateProperty.OverrideMetadata(typeof(BooleanStateDefinition), StateProperty.DefaultMetadata.with(coerce_state));
|
||||
object coerce_state(DependencyObject d, object baseValue) {
|
||||
var csd = (CheckedStateDefinition)d;
|
||||
var csd = (BooleanStateDefinition)d;
|
||||
return new StringBuilderEx(
|
||||
csd.Mode?.ToString() ?? string.Empty,
|
||||
csd._is_checked ? csd.CheckedState : csd.UncheckedState).ToString();
|
||||
csd._value ? csd.TrueState : csd.FalseState).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#region Mode
|
||||
public static readonly DependencyProperty ModeProperty =
|
||||
WPFHelper.create_dp<object, CheckedStateDefinition>(nameof(Mode), new PropertyMetadata(null, OnModeChanged));
|
||||
WPFHelper.create_dp<object, BooleanStateDefinition>(nameof(Mode), new PropertyMetadata(null, OnModeChanged));
|
||||
|
||||
static void OnModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => d.CoerceValue(StateProperty);
|
||||
|
||||
@@ -144,44 +144,83 @@ namespace mbts.ui {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CheckableSource
|
||||
public static readonly DependencyProperty CheckableSourceProperty =
|
||||
WPFHelper.create_dp<FrameworkElement, CheckedStateDefinition>(
|
||||
nameof(CheckableSource),
|
||||
(o, v) => o._on_checkable_source_changed(v));
|
||||
#region Source
|
||||
public static readonly DependencyProperty SourceProperty =
|
||||
WPFHelper.create_dp<FrameworkElement, BooleanStateDefinition>(
|
||||
nameof(Source),
|
||||
(o, v) => o._on_source_changed(v));
|
||||
|
||||
public FrameworkElement CheckableSource {
|
||||
get => GetValue(CheckableSourceProperty) as FrameworkElement;
|
||||
set => SetValue(CheckableSourceProperty, value);
|
||||
public FrameworkElement Source {
|
||||
get => GetValue(SourceProperty) as FrameworkElement;
|
||||
set => SetValue(SourceProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public string CheckedState { get; set; } = "Checked";
|
||||
public string UncheckedState { get; set; } = "Unchecked";
|
||||
public string TrueState { get; set; } = "True";
|
||||
public string FalseState { get; set; } = "False";
|
||||
|
||||
void _on_checkable_source_changed(FrameworkElement checkable_source) {
|
||||
Disposable.replace(ref _checkable_source_hook,
|
||||
OneOf.infer<IObservable<bool>, ToggleButton, MenuItem>(
|
||||
checkable_source, subscribe_toggle_button, subscribe_menu_item)
|
||||
?.Subscribe(on_checked_changed));
|
||||
void _on_source_changed(FrameworkElement source) {
|
||||
Disposable.replace(ref _source_hook,
|
||||
OneOf.infer<IObservable<bool>, ToggleButton, MenuItem, TabItem>(
|
||||
source, subscribe_toggle_button, subscribe_menu_item, susbcribe_tab_item)
|
||||
?.Subscribe(on_value_changed));
|
||||
|
||||
IObservable<bool> susbcribe_tab_item(TabItem ti) {
|
||||
on_value_changed(ti.IsSelected);
|
||||
return ti.ObserveIsSelected();
|
||||
}
|
||||
|
||||
IObservable<bool> subscribe_toggle_button(ToggleButton tb) {
|
||||
on_checked_changed(tb.IsChecked ?? false);
|
||||
on_value_changed(tb.IsChecked ?? false);
|
||||
return tb.ObserveIsChecked();
|
||||
}
|
||||
|
||||
IObservable<bool> subscribe_menu_item(MenuItem mi) {
|
||||
on_checked_changed(mi.IsChecked);
|
||||
on_value_changed(mi.IsChecked);
|
||||
return mi.ObserveIsChecked();
|
||||
}
|
||||
|
||||
void on_checked_changed(bool is_checked) {
|
||||
_is_checked = is_checked;
|
||||
void on_value_changed(bool value) {
|
||||
_value = value;
|
||||
CoerceValue(StateProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CheckedStateDefinition : BooleanStateDefinition {
|
||||
public CheckedStateDefinition() {
|
||||
CheckedState = "Checked";
|
||||
UncheckedState = "Unchecked";
|
||||
}
|
||||
|
||||
public string CheckedState {
|
||||
get => TrueState;
|
||||
set => TrueState = value;
|
||||
}
|
||||
|
||||
public string UncheckedState {
|
||||
get => FalseState;
|
||||
set => FalseState = value;
|
||||
}
|
||||
}
|
||||
|
||||
class SelectedStateDefinition : BooleanStateDefinition {
|
||||
public SelectedStateDefinition() {
|
||||
SelectedState = "Selected";
|
||||
UnselectedState = "Unselected";
|
||||
}
|
||||
|
||||
public string SelectedState {
|
||||
get => TrueState;
|
||||
set => TrueState = value;
|
||||
}
|
||||
|
||||
public string UnselectedState {
|
||||
get => FalseState;
|
||||
set => FalseState = value;
|
||||
}
|
||||
}
|
||||
|
||||
class ModalStateDefinition : StateDefinition {
|
||||
StateDefinition _source;
|
||||
|
||||
|
||||
Reference in new issue
Block a user