Skip to content

Commit

Permalink
Add IconAndText control
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Apr 24, 2024
1 parent 3be24e6 commit 1d83acc
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
26 changes: 5 additions & 21 deletions sample/ExamplePhotoTaker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,11 @@
<Viewbox>
<Viewbox x:Name="Viewbox_Viewport" Width="960">
<Border Background="White" Padding="10" Width="640" Height="320">
<TabControl Style="{StaticResource {x:Static ui:ThemeKeys.TabControlPivotStyleKey}}" >

<TabItem Header="TabItem 1">
<ui:TabItemHelper.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Shop}" FontSize="20"/>
</ui:TabItemHelper.Icon>
<TextBlock Text="Content 1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</TabItem>

<TabItem Header="TabItem 2">
<ui:TabItemHelper.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Settings}" FontSize="20"/>
</ui:TabItemHelper.Icon>
<TextBlock Text="Content 2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</TabItem>

<TabItem Header="TabItem 3">
<TextBlock Text="Content 3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</TabItem>

</TabControl>
<ui:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Button>
<ui:IconAndText Icon="{x:Static ui:SegoeFluentIcons.Save}" Content="Save"/>
</Button>
</ui:SimpleStackPanel>
</Border>
</Viewbox>
</Viewbox>
Expand Down
44 changes: 44 additions & 0 deletions source/iNKORE.UI.WPF.Modern/Controls/IconAndText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace iNKORE.UI.WPF.Modern.Controls
{
public class IconAndText : ContentControl
{
static IconAndText()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(IconAndText), new FrameworkPropertyMetadata(typeof(IconAndText)));
}

#region Properties

public static readonly DependencyProperty IconProperty = FontIcon.IconProperty.AddOwner(typeof(IconAndText));
public FontIconData? Icon
{
get { return (FontIconData?)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}

public static readonly DependencyProperty SpacingProperty = SimpleStackPanel.SpacingProperty.AddOwner(typeof(IconAndText), new PropertyMetadata(6d));
public double Spacing
{
get { return (double)GetValue(SpacingProperty); }
set { SetValue(SpacingProperty, value); }
}

public static readonly DependencyProperty OrientationProperty = SimpleStackPanel.OrientationProperty.AddOwner(typeof(IconAndText), new PropertyMetadata(Orientation.Horizontal));
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}

#endregion
}
}
42 changes: 42 additions & 0 deletions source/iNKORE.UI.WPF.Modern/Controls/IconAndText.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:iNKORE.UI.WPF.Modern.Controls"
xmlns:ch="clr-namespace:iNKORE.UI.WPF.Modern.Controls.Helpers"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style TargetType="local:IconAndText">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:IconAndText">
<Border x:Name="Root" Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding ch:ControlHelper.CornerRadius}">
<local:SimpleStackPanel x:Name="RootLayout" Orientation="{TemplateBinding Orientation}" Spacing="{TemplateBinding Spacing}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">

<local:FontIcon x:Name="Icon" Icon="{TemplateBinding Icon}"
FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<local:ContentPresenterEx x:Name="ContentPresenter" Content="{TemplateBinding Content}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>

</local:SimpleStackPanel>
</Border>

<ControlTemplate.Triggers>

<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="RootLayout" Property="Spacing" Value="0"/>
</Trigger>
<Trigger Property="Content" Value="{x:Null}">
<Setter TargetName="RootLayout" Property="Spacing" Value="0"/>
</Trigger>

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

</ResourceDictionary>
1 change: 1 addition & 0 deletions source/iNKORE.UI.WPF.Modern/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Controls/Frame.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Controls/Page.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Controls/ThumbEx.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Controls/IconAndText.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Themes/FontIconFallback.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Themes/ListViewHeaderItem.xaml" />
<ResourceDictionary Source="/iNKORE.UI.WPF.Modern;component/Themes/TextContextMenu.xaml" />
Expand Down

0 comments on commit 1d83acc

Please sign in to comment.