complete the branch

This commit is contained in:
NaBian committed 2019-01-29 20:12:17 +08:00
1 parent 2c0889f64b
commit cb20ea41f6
29 files changed
+426 -115

No files matched your search

+6 -4
View File
@@ -34,31 +34,33 @@ namespace HandyControl.Controls
if (!IsSelected)
{
IsSelected = true;
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
OnSelected(new RoutedEventArgs(SelectedEvent, this));
}
else if (CanDeselect)
{
IsSelected = false;
RaiseEvent(new RoutedEventArgs(DeselectedEvent, this));
OnSelected(new RoutedEventArgs(DeselectedEvent, this));
}
}
else
{
if (CanDeselect)
{
RaiseEvent(IsSelected
OnSelected(IsSelected
? new RoutedEventArgs(DeselectedEvent, this)
: new RoutedEventArgs(SelectedEvent, this));
}
else
{
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
OnSelected(new RoutedEventArgs(SelectedEvent, this));
}
}
_isMouseLeftButtonDown = false;
}
}
protected virtual void OnSelected(RoutedEventArgs e) => RaiseEvent(e);
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
+37 -3
View File
@@ -1,10 +1,10 @@
using System.Windows;
using System.Windows.Controls;
using System;
using System.Windows;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class ChatBubble : ContentControl
public class ChatBubble : SelectableItem
{
public static readonly DependencyProperty RoleProperty = DependencyProperty.Register(
"Role", typeof(ChatRoleType), typeof(ChatBubble), new PropertyMetadata(default(ChatRoleType)));
@@ -14,5 +14,39 @@ namespace HandyControl.Controls
get => (ChatRoleType) GetValue(RoleProperty);
set => SetValue(RoleProperty, value);
}
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
"Type", typeof(ChatMessageType), typeof(ChatBubble), new PropertyMetadata(default(ChatMessageType)));
public ChatMessageType Type
{
get => (ChatMessageType) GetValue(TypeProperty);
set => SetValue(TypeProperty, value);
}
public static readonly DependencyProperty IsReadProperty = DependencyProperty.Register(
"IsRead", typeof(bool), typeof(ChatBubble), new PropertyMetadata(ValueBoxes.FalseBox));
public bool IsRead
{
get => (bool) GetValue(IsReadProperty);
set => SetValue(IsReadProperty, value);
}
public static void SetMaxWidth(DependencyObject element, double value)
=> element.SetValue(MaxWidthProperty, value);
public static double GetMaxWidth(DependencyObject element)
=> (double) element.GetValue(MaxWidthProperty);
public Action<object> ReadAction { get; set; }
protected override void OnSelected(RoutedEventArgs e)
{
base.OnSelected(e);
IsRead = true;
ReadAction?.Invoke(Content);
}
}
}
+1 -1
View File
@@ -289,7 +289,7 @@ namespace HandyControl.Controls
throw new InvalidEnumArgumentException(nameof(defaultResult), (int)defaultResult, typeof(MessageBoxResult));
}
var ownerWindow = owner ?? Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
var ownerWindow = owner ?? VisualHelper.GetActiveWindow();
var ownerIsNull = ownerWindow is null;
return new MessageBox
+10
View File
@@ -0,0 +1,10 @@
namespace HandyControl.Data
{
public enum ChatMessageType
{
String,
Image,
Audio,
Custom
}
}
+1
View File
@@ -157,6 +157,7 @@
<Compile Include="Controls\Window\BlurWindow.cs" />
<Compile Include="Controls\Window\MessageBox.cs" />
<Compile Include="Data\Args\CancelRoutedEventArgs.cs" />
<Compile Include="Data\Enum\ChatMessageType.cs" />
<Compile Include="Data\Enum\ChatRoleType.cs" />
<Compile Include="Data\Enum\InfoType.cs" />
<Compile Include="Data\Enum\ResultType.cs" />
@@ -3,48 +3,134 @@
xmlns:controls="clr-namespace:HandyControl.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Basic/Converters.xaml"/>
<ResourceDictionary Source="../../Basic/Geometries.xaml"/>
<ResourceDictionary Source="../../Basic/Sizes.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ControlTemplate x:Key="ChatBubbleSenderBaseTemplate" TargetType="controls:ChatBubble">
<ControlTemplate x:Key="ChatBubbleStringBaseTemplate" TargetType="controls:ChatBubble">
<Grid>
<Path Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15"/>
<Border Background="{TemplateBinding Background}" CornerRadius="15" Margin="0,0,3,0">
<ContentPresenter Name="Presenter" Margin="{TemplateBinding Padding}" VerticalAlignment="Center">
<ContentPresenter.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<Border Background="White" CornerRadius="10" Width="{Binding ActualWidth,ElementName=Presenter}" Height="{Binding ActualHeight,ElementName=Presenter}"/>
</VisualBrush.Visual>
</VisualBrush>
</ContentPresenter.OpacityMask>
</ContentPresenter>
<Path Name="Tail" Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15" RenderTransformOrigin="0.5,0.5"/>
<Border Name="Body" Background="{TemplateBinding Background}" CornerRadius="15" Margin="0,0,3,0">
<TextBlock TextWrapping="Wrap" Text="{TemplateBinding Content}" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Role" Value="Receiver">
<Setter TargetName="Tail" Property="HorizontalAlignment" Value="Left"/>
<Setter TargetName="Tail" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="Body" Property="Margin" Value="3,0,0,0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ChatBubbleReceiverBaseTemplate" TargetType="controls:ChatBubble">
<ControlTemplate x:Key="ChatBubbleImageBaseTemplate" TargetType="controls:ChatBubble">
<Grid>
<Path Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Left" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Path.RenderTransform>
</Path>
<Border Background="{TemplateBinding Background}" CornerRadius="15" Margin="3,0,0,0">
<ContentPresenter Name="Presenter" Margin="{TemplateBinding Padding}" VerticalAlignment="Center">
<ContentPresenter.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<Border Background="White" CornerRadius="10" Width="{Binding ActualWidth,ElementName=Presenter}" Height="{Binding ActualHeight,ElementName=Presenter}"/>
</VisualBrush.Visual>
</VisualBrush>
</ContentPresenter.OpacityMask>
</ContentPresenter>
<Path Name="Tail" Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15" RenderTransformOrigin="0.5,0.5"/>
<Border Name="Body" Background="{TemplateBinding Background}" CornerRadius="15" Margin="0,0,3,0">
<Grid>
<Image Margin="{TemplateBinding Padding}" VerticalAlignment="Center" Source="{TemplateBinding Content}"/>
<Border BorderThickness="{TemplateBinding Padding}" BorderBrush="{TemplateBinding Background}" Background="{x:Null}" CornerRadius="15"/>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Role" Value="Receiver">
<Setter TargetName="Tail" Property="HorizontalAlignment" Value="Left"/>
<Setter TargetName="Tail" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="Body" Property="Margin" Value="3,0,0,0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ChatBubbleAudioBaseTemplate" TargetType="controls:ChatBubble">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12" Name="Definition1"/>
<ColumnDefinition Name="Definition2"/>
</Grid.ColumnDefinitions>
<Ellipse Name="Dot" VerticalAlignment="Top" Fill="{DynamicResource DangerBrush}" Width="6" Height="6" Visibility="{TemplateBinding IsRead,Converter={StaticResource Boolean2BooleanReConverter}}" Margin="0,0,6,0"/>
<Path Name="Tail" Grid.Column="1" Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15" RenderTransformOrigin="0.5,0.5"/>
<Border Name="Body" Grid.Column="1" Background="{TemplateBinding Background}" CornerRadius="15" Margin="0,0,3,0">
<Grid VerticalAlignment="Center" Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter Name="Presenter" VerticalAlignment="Center"/>
<Path Name="Audio" Grid.Column="1" Data="{StaticResource AudioGeometry}" Fill="{TemplateBinding Foreground}" Width="16" Height="16" Margin="6,0,0,0" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Role" Value="Receiver">
<Setter TargetName="Tail" Property="HorizontalAlignment" Value="Left"/>
<Setter TargetName="Tail" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="Tail" Property="Grid.Column" Value="0"/>
<Setter TargetName="Dot" Property="Grid.Column" Value="1"/>
<Setter TargetName="Dot" Property="Margin" Value="6,0,0,0"/>
<Setter TargetName="Body" Property="Margin" Value="3,0,0,0"/>
<Setter TargetName="Body" Property="Grid.Column" Value="0"/>
<Setter TargetName="Definition1" Property="Width" Value="Auto"/>
<Setter TargetName="Definition2" Property="Width" Value="12"/>
<Setter TargetName="Audio" Property="Grid.Column" Value="0"/>
<Setter TargetName="Audio" Property="Margin" Value="0,0,6,0"/>
<Setter TargetName="Audio" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="1"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="Presenter" Property="Grid.Column" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ChatBubbleCustomBaseTemplate" TargetType="controls:ChatBubble">
<Grid>
<Path Name="Tail" Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15" RenderTransformOrigin="0.5,0.5"/>
<Border Name="Body" Background="{TemplateBinding Background}" CornerRadius="15" Margin="0,0,3,0">
<ContentPresenter VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Role" Value="Receiver">
<Setter TargetName="Tail" Property="HorizontalAlignment" Value="Left"/>
<Setter TargetName="Tail" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="-1"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="Body" Property="Margin" Value="3,0,0,0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="ChatBubbleBaseStyle" TargetType="controls:ChatBubble">
@@ -54,14 +140,25 @@
<Setter Property="Padding" Value="10"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="MinHeight" Value="{StaticResource DefaultControlHeight}"/>
<Setter Property="Template" Value="{StaticResource ChatBubbleSenderBaseTemplate}"/>
<Setter Property="Template" Value="{StaticResource ChatBubbleStringBaseTemplate}"/>
<Setter Property="IsRead" Value="{Binding IsSelected,RelativeSource={RelativeSource Self}}"/>
<Setter Property="MaxWidth" Value="280"/>
<Style.Triggers>
<Trigger Property="Role" Value="Receiver">
<Setter Property="Template" Value="{StaticResource ChatBubbleReceiverBaseTemplate}"/>
<Setter Property="Background" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Trigger>
<Trigger Property="Type" Value="Image">
<Setter Property="Template" Value="{StaticResource ChatBubbleImageBaseTemplate}"/>
<Setter Property="MaxHeight" Value="280"/>
</Trigger>
<Trigger Property="Type" Value="Audio">
<Setter Property="Template" Value="{StaticResource ChatBubbleAudioBaseTemplate}"/>
</Trigger>
<Trigger Property="Type" Value="Custom">
<Setter Property="Template" Value="{StaticResource ChatBubbleCustomBaseTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>
+16 -1
View File
@@ -9,7 +9,22 @@
<ResourceDictionary Source="ListBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="controls:Carousel" BasedOn="{StaticResource StackPanelListBox}">
<Style x:Key="CarouselListBoxItemStyle" BasedOn="{StaticResource ListBoxItemCustom}" TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Height" Value="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
</Style>
<ItemsPanelTemplate x:Key="CarouselListBoxItemPanelTemplate">
<StackPanel FocusVisualStyle="{x:Null}" Orientation="Horizontal" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
<Style x:Key="CarouselListBox" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource CarouselListBoxItemPanelTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource CarouselListBoxItemStyle}"/>
</Style>
<Style TargetType="controls:Carousel" BasedOn="{StaticResource CarouselListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Carousel">
+26 -13
View File
@@ -8,7 +8,7 @@
<!--默认样式-->
<Style BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Style x:Key="ListBoxItemCustom" TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Padding" Value="0"/>
@@ -26,28 +26,41 @@
</Setter>
</Style>
<Style x:Key="ListBoxItemFullStyle" BasedOn="{StaticResource ListBoxItemStyle}" TargetType="ListBoxItem">
<Style x:Key="ListBoxCustom" TargetType="ListBox">
<Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemCustom}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Height" Value="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>
</Style>
<ItemsPanelTemplate x:Key="WrapPanelItemsPanelTemplate">
<ItemsPanelTemplate x:Key="WrapPanelHorizontalItemsPanelTemplate">
<WrapPanel FocusVisualStyle="{x:Null}"/>
</ItemsPanelTemplate>
<Style x:Key="WrapPanelListBox" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource WrapPanelItemsPanelTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemStyle}"/>
<Style x:Key="WrapPanelHorizontalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource WrapPanelHorizontalItemsPanelTemplate}"/>
</Style>
<ItemsPanelTemplate x:Key="StackPanelItemsPanelTemplate">
<StackPanel FocusVisualStyle="{x:Null}" Orientation="Horizontal" HorizontalAlignment="Left"/>
<ItemsPanelTemplate x:Key="WrapPanelVerticalItemsPanelTemplate">
<WrapPanel FocusVisualStyle="{x:Null}" Orientation="Vertical"/>
</ItemsPanelTemplate>
<Style x:Key="StackPanelListBox" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource StackPanelItemsPanelTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemFullStyle}"/>
<Style x:Key="WrapPanelVerticalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource WrapPanelVerticalItemsPanelTemplate}"/>
</Style>
<ItemsPanelTemplate x:Key="StackPanelHorizontalItemsPanelTemplate">
<StackPanel FocusVisualStyle="{x:Null}" Orientation="Horizontal"/>
</ItemsPanelTemplate>
<Style x:Key="StackPanelHorizontalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource StackPanelHorizontalItemsPanelTemplate}"/>
</Style>
<ItemsPanelTemplate x:Key="StackPanelVerticalItemsPanelTemplate">
<StackPanel FocusVisualStyle="{x:Null}" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
<Style x:Key="StackPanelVerticalListBox" BasedOn="{StaticResource ListBoxCustom}" TargetType="ListBox">
<Setter Property="ItemsPanel" Value="{StaticResource StackPanelVerticalItemsPanelTemplate}"/>
</Style>
</ResourceDictionary>
+5 -3
View File
@@ -4,9 +4,9 @@ using System.Windows.Media;
namespace HandyControl.Tools
{
internal class VisualHelper
public class VisualHelper
{
public static VisualStateGroup TryGetVisualStateGroup(DependencyObject dependencyObject, string groupName)
internal static VisualStateGroup TryGetVisualStateGroup(DependencyObject dependencyObject, string groupName)
{
var root = GetImplementationRoot(dependencyObject);
if (root == null)
@@ -20,11 +20,13 @@ namespace HandyControl.Tools
.FirstOrDefault(group => string.CompareOrdinal(groupName, group.Name) == 0);
}
public static FrameworkElement GetImplementationRoot(DependencyObject dependencyObject)
internal static FrameworkElement GetImplementationRoot(DependencyObject dependencyObject)
{
return 1 == VisualTreeHelper.GetChildrenCount(dependencyObject)
? VisualTreeHelper.GetChild(dependencyObject, 0) as FrameworkElement
: null;
}
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
}
}