-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 添加支持圆角的 ToggleButton, 修复 TransitioningContentControl 模板应用较晚导致的内…
…容不显示 bug
- Loading branch information
Showing
14 changed files
with
273 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace EleCho.WpfSuite | ||
{ | ||
public class ToggleButton : System.Windows.Controls.Primitives.ToggleButton | ||
{ | ||
static ToggleButton() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ToggleButton), new FrameworkPropertyMetadata(typeof(ToggleButton))); | ||
} | ||
|
||
public CornerRadius CornerRadius | ||
{ | ||
get { return (CornerRadius)GetValue(CornerRadiusProperty); } | ||
set { SetValue(CornerRadiusProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty CornerRadiusProperty = | ||
Border.CornerRadiusProperty.AddOwner(typeof(ToggleButton)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite"> | ||
|
||
<Style x:Key="FocusVisual"> | ||
<Setter Property="Control.Template"> | ||
<Setter.Value> | ||
<ControlTemplate> | ||
<Rectangle Margin="2" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/> | ||
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/> | ||
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/> | ||
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/> | ||
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/> | ||
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/> | ||
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/> | ||
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/> | ||
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/> | ||
<Style TargetType="{x:Type ws:ToggleButton}"> | ||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> | ||
<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/> | ||
<Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/> | ||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> | ||
<Setter Property="BorderThickness" Value="1"/> | ||
<Setter Property="HorizontalContentAlignment" Value="Center"/> | ||
<Setter Property="VerticalContentAlignment" Value="Center"/> | ||
<Setter Property="Padding" Value="1"/> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="{x:Type ws:ToggleButton}"> | ||
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" SnapsToDevicePixels="true"> | ||
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<Trigger Property="Button.IsDefaulted" Value="true"> | ||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | ||
</Trigger> | ||
<Trigger Property="IsMouseOver" Value="true"> | ||
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/> | ||
</Trigger> | ||
<Trigger Property="IsPressed" Value="true"> | ||
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/> | ||
</Trigger> | ||
<Trigger Property="IsEnabled" Value="false"> | ||
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/> | ||
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/> | ||
</Trigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<Page x:Class="WpfTest.Tests.ConditionalControlTestPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:WpfTest.Tests" | ||
xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
d:Background="White" | ||
Title="ConditionalControlTestPage"> | ||
|
||
<ws:ScrollViewer ScrollWithWheelDelta="True" | ||
VerticalScrollBarVisibility="Auto"> | ||
<ws:StackPanel Margin="28 12 28 28" | ||
Spacing="12"> | ||
<TextBlock Text="ConditionalControl Test" | ||
FontSize="26" | ||
Margin="0 0 0 12"/> | ||
<ws:ConditionalControl Condition="{Binding ElementName=ConditionButton,Path=IsChecked}" | ||
ContentWhenTrue="{Binding ElementName=ContentWhenTrueBox,Path=Text}" | ||
ContentWhenFalse="{Binding ElementName=ContentWhenFalseBox,Path=Text}"> | ||
<ws:ConditionalControl.Transition> | ||
<ws:SlideFadeTransition Orientation="Vertical" | ||
Distance="10"/> | ||
</ws:ConditionalControl.Transition> | ||
<ws:ConditionalControl.ContentTemplateWhenTrue> | ||
<DataTemplate> | ||
<Border BorderBrush="Green" | ||
BorderThickness="3" | ||
CornerRadius="3" | ||
Padding="5"> | ||
<ws:StackPanel Spacing="4"> | ||
<TextBlock Text="Current value is true"/> | ||
<TextBlock> | ||
<Run Text="Content:"/> | ||
<Run Text="{Binding Mode=OneWay}"/> | ||
</TextBlock> | ||
</ws:StackPanel> | ||
</Border> | ||
</DataTemplate> | ||
</ws:ConditionalControl.ContentTemplateWhenTrue> | ||
<ws:ConditionalControl.ContentTemplateWhenFalse> | ||
<DataTemplate> | ||
<Border BorderBrush="Red" | ||
BorderThickness="3" | ||
CornerRadius="3" | ||
Padding="5"> | ||
<ws:StackPanel Spacing="4"> | ||
<TextBlock Text="Current value is true"/> | ||
<TextBlock> | ||
<Run Text="Content:"/> | ||
<Run Text="{Binding Mode=OneWay}"/> | ||
</TextBlock> | ||
</ws:StackPanel> | ||
</Border> | ||
</DataTemplate> | ||
</ws:ConditionalControl.ContentTemplateWhenFalse> | ||
</ws:ConditionalControl> | ||
|
||
<GroupBox Header="Options" | ||
Padding="8"> | ||
<ws:FlexPanel Direction="Column" | ||
MainSpacing="8" | ||
ItemsAlignment="Start"> | ||
<ws:ToggleButton x:Name="ConditionButton" | ||
Content="Toggle Condition" | ||
Padding="5 3" | ||
CornerRadius="3"/> | ||
<StackPanel> | ||
<TextBlock Text="ContentWhenTrue:"/> | ||
<ws:TextBox x:Name="ContentWhenTrueBox" | ||
Placeholder="ContentWhenTrue" | ||
Text="TrueContent" | ||
MinWidth="150" | ||
Padding="5 3"/> | ||
</StackPanel> | ||
<StackPanel> | ||
<TextBlock Text="ContentWhenFalse:"/> | ||
<ws:TextBox x:Name="ContentWhenFalseBox" | ||
Placeholder="ContentWhenTrue" | ||
Text="FalseContent" | ||
MinWidth="150" | ||
Padding="5 3"/> | ||
</StackPanel> | ||
</ws:FlexPanel> | ||
</GroupBox> | ||
</ws:StackPanel> | ||
</ws:ScrollViewer> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace WpfTest.Tests | ||
{ | ||
/// <summary> | ||
/// ConditionalControlTestPage.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class ConditionalControlTestPage : Page | ||
{ | ||
public ConditionalControlTestPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
Oops, something went wrong.