add role property

This commit is contained in:
NaBian committed 2019-01-29 00:16:09 +08:00
1 parent 8c372510f5
commit 2c0889f64b
24 files changed
+284 -87

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ namespace HandyControl.Controls
if (_textBox != null)
{
_textBox.TextChanged -= TextBox_TextChanged;
_textBox.KeyDown -= TextBox_KeyDown;
}
base.OnApplyTemplate();
+10 -6
View File
@@ -1,14 +1,18 @@
using System.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class ChatBubble : ContentControl
{
public static readonly DependencyProperty RoleProperty = DependencyProperty.Register(
"Role", typeof(ChatRoleType), typeof(ChatBubble), new PropertyMetadata(default(ChatRoleType)));
//public ChatBubble(object message)
//{
//}
public ChatRoleType Role
{
get => (ChatRoleType) GetValue(RoleProperty);
set => SetValue(RoleProperty, value);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace HandyControl.Data
{
public enum ChatRoleType
{
Sender,
Receiver
}
}
+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\ChatRoleType.cs" />
<Compile Include="Data\Enum\InfoType.cs" />
<Compile Include="Data\Enum\ResultType.cs" />
<Compile Include="Data\Enum\SkinType.cs" />
@@ -7,23 +7,62 @@
<ResourceDictionary Source="../../Basic/Sizes.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ControlTemplate x:Key="ChatBubbleSenderBaseTemplate" 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>
</Border>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ChatBubbleReceiverBaseTemplate" 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>
</Border>
</Grid>
</ControlTemplate>
<Style x:Key="ChatBubbleBaseStyle" TargetType="controls:ChatBubble">
<Setter Property="Background" Value="{DynamicResource PrimaryBrush}"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Background" Value="{DynamicResource DarkPrimaryBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}"/>
<Setter Property="Padding" Value="10,0"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="MinHeight" Value="{StaticResource DefaultControlHeight}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:ChatBubble">
<Grid>
<Border Background="{TemplateBinding Background}" CornerRadius="15">
<ContentPresenter Margin="{TemplateBinding Padding}" VerticalAlignment="Center"/>
</Border>
<Path Data="{StaticResource BubbleTailGeometry}" Fill="{TemplateBinding Background}" HorizontalAlignment="Right" Stretch="Uniform" VerticalAlignment="Bottom" Width="15" Height="15"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template" Value="{StaticResource ChatBubbleSenderBaseTemplate}"/>
<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>
</Style.Triggers>
</Style>
</ResourceDictionary>