Skip to content

Commit

Permalink
Add TextBox Control #8
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Dec 6, 2024
1 parent b3030a3 commit 7335ffa
Show file tree
Hide file tree
Showing 11 changed files with 755 additions and 18 deletions.
44 changes: 44 additions & 0 deletions dev/DevWinUI.Controls/Controls/TextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.UI.Input;
using Microsoft.UI.Xaml.Markup;

namespace DevWinUI;

[ContentProperty(Name = nameof(Content))]
public partial class TextBox : Microsoft.UI.Xaml.Controls.TextBox
{
public object Content
{
get { return (object)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}

public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(nameof(Content), typeof(object), typeof(TextBox), new PropertyMetadata(null, OnContentChanged));

private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (TextBox)d;
if (ctl != null )
{
ctl.UpdateCursor();
}
}

private void UpdateCursor()
{
if (Content != null)
{
if (Content is Button button)
{
GeneralHelper.ChangeCursor(button, InputSystemCursor.Create(InputSystemCursorShape.Arrow));
}
else if (Content is Panel panel)
{
foreach (var item in panel.Children)
{
GeneralHelper.ChangeCursor(item, InputSystemCursor.Create(InputSystemCursorShape.Arrow));
}
}
}
}
}
232 changes: 232 additions & 0 deletions dev/DevWinUI.Controls/Themes/Generic.xaml

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions dev/DevWinUI.Controls/Themes/Styles/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,95 @@

</ResourceDictionary.ThemeDictionaries>

<Style x:Name="TextBoxButtonStyle"
TargetType="Button">
<Setter Property="Padding" Value="{ThemeResource HelperButtonThemePadding}" />
<Setter Property="CornerRadius" Value="4" />
<Setter Property="Width" Value="30" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="AutomationProperties.AccessibilityView" Value="Raw" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="ButtonLayoutGrid"
Margin="{ThemeResource TextBoxInnerButtonMargin}"
Background="{ThemeResource TextControlButtonBackground}"
BackgroundSizing="{TemplateBinding BackgroundSizing}"
BorderBrush="{ThemeResource TextControlButtonBorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonBackgroundPointerOver}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonBorderBrushPointerOver}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonForegroundPointerOver}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonBackgroundPressed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonBorderBrushPressed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource TextControlButtonForegroundPressed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ButtonLayoutGrid"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Viewbox Width="12"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ContentPresenter x:Name="GlyphElement"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
Content="{TemplateBinding Content}"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="{ThemeResource TextBoxIconFontSize}"
FontStyle="Normal"
Foreground="{ThemeResource TextControlButtonForeground}" />
</Viewbox>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="SubtleButtonStyle"
TargetType="Button">
<Setter Property="Background" Value="{ThemeResource SubtleButtonBackground}" />
Expand Down
Loading

0 comments on commit 7335ffa

Please sign in to comment.