Skip to content

Commit

Permalink
#77 Fix issue
Browse files Browse the repository at this point in the history
#77 Fix issue
  • Loading branch information
yanjinhuagood committed Jan 13, 2024
1 parent 4f17517 commit 9594166
Show file tree
Hide file tree
Showing 16 changed files with 354 additions and 101 deletions.
5 changes: 1 addition & 4 deletions src/WPFDevelopers.Net40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2623,10 +2623,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<Border.Background>
<SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=Background}" />
</Border.Background>
<Border x:Name="DGR_Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down
7 changes: 1 addition & 6 deletions src/WPFDevelopers.Net45x/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="PART_Border" Property="Fill" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
<Setter TargetName="PART_Border" Property="Stroke" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
Expand Down Expand Up @@ -1691,7 +1690,6 @@
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="PART_Border" Property="Background" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
</Trigger>
<Trigger Property="IsChecked" Value="{x:Null}">
<Trigger.EnterActions>
Expand Down Expand Up @@ -2626,10 +2624,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridRow}">
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<Border.Background>
<SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=Background}" />
</Border.Background>
<Border x:Name="DGR_Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<SelectiveScrollingGrid>
<SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down
70 changes: 48 additions & 22 deletions src/WPFDevelopers.Samples.Shared/ExampleViews/ScreenCutExample.xaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
<UserControl x:Class="WPFDevelopers.Samples.ExampleViews.ScreenCutExample"
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:WPFDevelopers.Samples.ExampleViews"
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl
x:Class="WPFDevelopers.Samples.ExampleViews.ScreenCutExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<controls:CodeViewer>
<UniformGrid Rows="2">
<CheckBox Content="截图时隐藏当前窗口"
VerticalAlignment="Bottom" HorizontalAlignment="Center"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ScreenCutExample}}, Path=IsChecked}"/>
<Button Content="截屏" VerticalAlignment="Top" HorizontalAlignment="Center" Click="Button_Click"
Margin="0,10"/>
</UniformGrid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox
Margin="0,10,0,10"
HorizontalAlignment="Center"
Content="截图时隐藏当前窗口"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ScreenCutExample}}, Path=IsChecked}" />
<Button
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Click="Button_Click"
Content="截屏" />
<Button
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Click="ButtonExt_Click"
Content="截屏Ext"
Style="{StaticResource WD.SuccessPrimaryButton}" />
<Image
x:Name="myImage"
Grid.Row="2"
Grid.ColumnSpan="2"
Stretch="Uniform" />
</Grid>
<controls:CodeViewer.SourceCodes>
<controls:SourceCodeModel
CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ScreenCutExample.xaml"
CodeType="Xaml"/>
<controls:SourceCodeModel
CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ScreenCutExample.xaml.cs"
CodeType="CSharp"/>
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ScreenCutExample.xaml" CodeType="Xaml" />
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ScreenCutExample.xaml.cs" CodeType="CSharp" />
</controls:CodeViewer.SourceCodes>
</controls:CodeViewer>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,37 @@ private void Button_Click(object sender, RoutedEventArgs e)
private void ScreenCapturer_SnapCanceled()
{
App.CurrentMainWindow.WindowState = WindowState.Normal;
Message.Push($"{DateTime.Now} 取消截图", MessageBoxImage.Information);
}

private void ScreenCapturer_SnapCompleted(System.Windows.Media.Imaging.CroppedBitmap bitmap)
{
myImage.Source = bitmap;
App.CurrentMainWindow.WindowState = WindowState.Normal;
}
private void ButtonExt_Click(object sender, RoutedEventArgs e)
{
if (IsChecked)
{
App.CurrentMainWindow.WindowState = WindowState.Minimized;
}

var screenCaptureExt = new ScreenCaptureExt();
screenCaptureExt.SnapCanceled += ScreenCaptureExt_SnapCanceled;
screenCaptureExt.SnapCompleted += ScreenCaptureExt_SnapCompleted;
}

private void ScreenCaptureExt_SnapCompleted(System.Windows.Media.Imaging.BitmapSource bitmap)
{
myImage.Source = bitmap;
App.CurrentMainWindow.WindowState = WindowState.Normal;
}

private void ScreenCaptureExt_SnapCanceled()
{
if (App.CurrentMainWindow.WindowState == WindowState.Minimized)
App.CurrentMainWindow.WindowState = WindowState.Normal;
Message.Push($"{DateTime.Now} 取消截图",MessageBoxImage.Information);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static void OnItemsSourcePropertyChanged(DependencyObject obj, Dependenc

foreach (var item in newValue)
{
ctrl._items.Add(new BubblleItem { Text = item, Bg = ControlsHelper.RandomBrush() });
ctrl._items.Add(new BubblleItem { Text = item, Bg = Helper.RandomBrush() });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ protected override Size ArrangeOverride(Size arrangeSize)
{
double xNum = x + 1;
xNum = _maxSize * xNum;
_bubbleItemX = ControlsHelper.NextDouble(left, xNum - _size * ControlsHelper.NextDouble(0.6, 0.9));
_bubbleItemX = Helper.NextDouble(left, xNum - _size * Helper.NextDouble(0.6, 0.9));
var _width = _bubbleItemX + _size;
_width = _width > width ? width - (width - _bubbleItemX) - _size : _bubbleItemX;
_bubbleItemX = _width;
_bubbleItemY = ControlsHelper.NextDouble(top, yNum - _size * ControlsHelper.NextDouble(0.6, 0.9));
_bubbleItemY = Helper.NextDouble(top, yNum - _size * Helper.NextDouble(0.6, 0.9));
var _height = _bubbleItemY + _size;
_height = _height > height ? height - (height - _bubbleItemY) - _size : _bubbleItemY;
_bubbleItemY = _height;
Expand All @@ -68,9 +68,9 @@ protected override Size ArrangeOverride(Size arrangeSize)
private void ResizeItem(FrameworkElement item)
{
if (DoubleUtil.GreaterThanOrClose(item.DesiredSize.Width, 55))
_size = ControlsHelper.GetRandom.Next(80, _maxSize);
_size = Helper.GetRandom.Next(80, _maxSize);
else
_size = ControlsHelper.GetRandom.Next(55, _maxSize);
_size = Helper.GetRandom.Next(55, _maxSize);
item.Width = _size;
item.Height = _size;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WPFDevelopers.Shared/Controls/CropAvatar/CropAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void InitialImage()
{
vNewStartX = 0;
vNewStartY = 0;
var uri = ControlsHelper.ImageUri();
var uri = Helper.ImageUri();
if (uri == null) return;
var bitmap = new BitmapImage();
bitmap.BeginInit();
Expand Down
11 changes: 6 additions & 5 deletions src/WPFDevelopers.Shared/Controls/CropImage/CropImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,18 @@ public override void OnApplyTemplate()

private void DrawImage()
{
if (Source == null)
if (Source == null) return;
if (_border.Visibility == Visibility.Visible)
{
_border.Visibility = Visibility.Collapsed;
if (adornerLayer == null) return;
_border.Visibility = Visibility.Visible;
}
if (adornerLayer != null)
{
adornerLayer.Remove(screenCutAdorner);
screenCutAdorner = null;
adornerLayer = null;
return;
}

_border.Visibility = Visibility.Visible;
var bitmap = (BitmapImage)Source;
bitmapFrame = ControlsHelper.CreateResizedImage(bitmap, (int)bitmap.Width, (int)bitmap.Height, 0);
_canvas.Width = bitmap.Width;
Expand Down
105 changes: 105 additions & 0 deletions src/WPFDevelopers.Shared/Controls/ScreenCut/ScreenCaptureExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace WPFDevelopers.Controls
{
public class ScreenCaptureExt : Window
{
const int WM_USER = 0x03FC;
const int MY_MESSAGE = WM_USER + 1;
/// <summary>
/// 截图完成委托
/// </summary>
public delegate void ScreenShotDone(BitmapSource bitmap);
/// <summary>
/// 截图完成事件
/// </summary>
public event ScreenShotDone SnapCompleted;
/// <summary>
/// 截图取消委托
/// </summary>
public delegate void ScreenShotCanceled();
/// <summary>
/// 截图取消事件
/// </summary>
public event ScreenShotCanceled SnapCanceled;

public ScreenCaptureExt()
{
Width = 0;
Height = 0;
Left = int.MinValue;
Top = int.MinValue;
WindowStyle = WindowStyle.None;
ShowInTaskbar = false;
ShowActivated = false;
Title = "ScreenShot";
Show();
ShowScreenShot();
}

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwndSource = PresentationSource.FromVisual(this) as HwndSource;
if (hwndSource != null) hwndSource.AddHook(WndProc);
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_USER:
GetClipboard();
Close();
break;
case MY_MESSAGE:
if (SnapCanceled != null)
SnapCanceled();
Close();
break;
}
return IntPtr.Zero;
}

void GetClipboard()
{
if (Clipboard.ContainsImage())
{
var dataObject = Clipboard.GetDataObject();
if (dataObject == null) return;

using (var memoryStream = new MemoryStream())
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)dataObject.GetData(DataFormats.Bitmap)));
encoder.Save(memoryStream);
memoryStream.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
bitmapImage.Freeze();
if (SnapCompleted != null)
SnapCompleted(bitmapImage);
}
}
}

void ShowScreenShot()
{
if (Helper.GetTempPathVersionExt != null && File.Exists(Helper.GetTempPathVersionExt))
{
var process = new Process();
process.StartInfo.FileName = Helper.GetTempPathVersionExt;
process.StartInfo.Arguments = Title;
process.Start();
}
}
}
}
2 changes: 1 addition & 1 deletion src/WPFDevelopers.Shared/Controls/ScreenCut/ScreenCut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ private void DrawArrowControl(Point current)
var renderOrigin = new Point(0, .5);
controlArrow.RenderTransformOrigin = renderOrigin;
controlArrow.RenderTransform = rotate;
rotate.Angle = ControlsHelper.CalculeAngle(vPoint, current);
rotate.Angle = Helper.CalculeAngle(vPoint, current);
if (current.X < rect.Left
||
current.X > rect.Right
Expand Down
Loading

0 comments on commit 9594166

Please sign in to comment.