Skip to content

Commit c358eb3

Browse files
committed
Add BoolStateContentControl and demo
1 parent f082fa0 commit c358eb3

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

src/Wpf.Ui.Test/MainWindow.xaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,35 @@
41204120
ButtonSpinner Demo
41214121
══════════════════════════════════════════════════════════════
41224122
-->
4123+
<!-- BoolStateContentControl -->
4124+
<StackPanel Margin="0,8,0,0">
4125+
<TextBlock
4126+
Margin="0,0,0,4"
4127+
FontSize="16"
4128+
FontWeight="SemiBold"
4129+
Text="BoolStateContentControl" />
4130+
<ui:StackPanel Orientation="Horizontal" Spacing="8">
4131+
<CheckBox
4132+
VerticalAlignment="Center"
4133+
Content="BoolState Value"
4134+
IsChecked="{Binding BoolStateDemoValue, Mode=TwoWay}" />
4135+
<vio:BoolStateContentControl Value="{Binding BoolStateDemoValue}">
4136+
<vio:BoolStateContentControl.TrueContent>
4137+
<ui:SymbolIcon
4138+
Filled="True"
4139+
Foreground="Green"
4140+
Symbol="CheckmarkCircle24" />
4141+
</vio:BoolStateContentControl.TrueContent>
4142+
<vio:BoolStateContentControl.FalseContent>
4143+
<ui:SymbolIcon
4144+
Filled="True"
4145+
Foreground="Red"
4146+
Symbol="DismissCircle24" />
4147+
</vio:BoolStateContentControl.FalseContent>
4148+
</vio:BoolStateContentControl>
4149+
</ui:StackPanel>
4150+
</StackPanel>
4151+
41234152
<!-- BoolStateTextBlock -->
41244153
<StackPanel Margin="0,8,0,0">
41254154
<TextBlock
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace Wpf.Ui.Violeta.Controls;
5+
6+
public class BoolStateContentControl : ContentControl
7+
{
8+
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
9+
nameof(Value),
10+
typeof(bool),
11+
typeof(BoolStateContentControl),
12+
new PropertyMetadata(false, OnStateChanged));
13+
14+
public static readonly DependencyProperty TrueContentProperty = DependencyProperty.Register(
15+
nameof(TrueContent),
16+
typeof(object),
17+
typeof(BoolStateContentControl),
18+
new PropertyMetadata(null, OnStateChanged));
19+
20+
public static readonly DependencyProperty FalseContentProperty = DependencyProperty.Register(
21+
nameof(FalseContent),
22+
typeof(object),
23+
typeof(BoolStateContentControl),
24+
new PropertyMetadata(null, OnStateChanged));
25+
26+
public bool Value
27+
{
28+
get => (bool)GetValue(ValueProperty);
29+
set => SetValue(ValueProperty, value);
30+
}
31+
32+
public object? TrueContent
33+
{
34+
get => GetValue(TrueContentProperty);
35+
set => SetValue(TrueContentProperty, value);
36+
}
37+
38+
public object? FalseContent
39+
{
40+
get => GetValue(FalseContentProperty);
41+
set => SetValue(FalseContentProperty, value);
42+
}
43+
44+
public BoolStateContentControl()
45+
{
46+
UpdateContent();
47+
}
48+
49+
private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
50+
{
51+
if (d is BoolStateContentControl ctrl)
52+
{
53+
ctrl.UpdateContent();
54+
}
55+
}
56+
57+
private void UpdateContent()
58+
{
59+
SetCurrentValue(ContentProperty, Value ? TrueContent : FalseContent);
60+
}
61+
}

0 commit comments

Comments
 (0)