Skip to content

Commit 04a72dc

Browse files
committed
#79 Add proportional scaling
Add proportional scaling #79
1 parent 683f32e commit 04a72dc

File tree

5 files changed

+281
-74
lines changed

5 files changed

+281
-74
lines changed

src/WPFDevelopers.Net40/Themes/Theme.xaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@
749749
<Style BasedOn="{x:Null}" TargetType="{x:Type wd:Window}">
750750
<Setter Property="Foreground" Value="{DynamicResource WD.RegularTextSolidColorBrush}" />
751751
<Setter Property="Background" Value="{DynamicResource WD.BackgroundSolidColorBrush}" />
752-
<Setter Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
753-
<Setter Property="TitleBackground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
752+
<Setter Property="BorderBrush" Value="{DynamicResource WD.WindowBorderBrushSolidColorBrush}" />
753+
<Setter Property="TitleBackground" Value="{DynamicResource WD.WindowBorderBrushSolidColorBrush}" />
754754
<Setter Property="IsTabStop" Value="False" />
755755
<Setter Property="BorderThickness" Value="1" />
756756
<Setter Property="SnapsToDevicePixels" Value="True" />
@@ -1060,7 +1060,6 @@
10601060
<Trigger Property="IsChecked" Value="True">
10611061
<Setter TargetName="PART_Border" Property="Fill" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
10621062
<Setter TargetName="PART_Border" Property="Stroke" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
1063-
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
10641063
</Trigger>
10651064
<MultiTrigger>
10661065
<MultiTrigger.Conditions>
@@ -1690,7 +1689,6 @@
16901689
<Trigger Property="IsChecked" Value="True">
16911690
<Setter TargetName="PART_Border" Property="Background" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
16921691
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
1693-
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
16941692
</Trigger>
16951693
<Trigger Property="IsChecked" Value="{x:Null}">
16961694
<Trigger.EnterActions>
@@ -2840,7 +2838,7 @@
28402838
<ScaleTransform ScaleX="0" ScaleY="1" />
28412839
</Border.RenderTransform>
28422840
</Border>
2843-
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2841+
<ContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
28442842
<VisualStateManager.VisualStateGroups>
28452843
<VisualStateGroup x:Name="SelectionStates">
28462844
<VisualState x:Name="Unselected" />
@@ -2861,10 +2859,10 @@
28612859
<Trigger Property="IsSelected" Value="True">
28622860
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28632861
<Setter Property="Background" Value="{DynamicResource WD.DefaultBackgroundSolidColorBrush}" />
2864-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2862+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28652863
</Trigger>
28662864
<Trigger Property="IsMouseOver" Value="True">
2867-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2865+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28682866
</Trigger>
28692867
</ControlTemplate.Triggers>
28702868
</ControlTemplate>
@@ -2888,7 +2886,7 @@
28882886
<ScaleTransform ScaleX="1" ScaleY="0" />
28892887
</Border.RenderTransform>
28902888
</Border>
2891-
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2889+
<ContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
28922890
<VisualStateManager.VisualStateGroups>
28932891
<VisualStateGroup x:Name="SelectionStates">
28942892
<VisualState x:Name="Unselected" />
@@ -2909,10 +2907,10 @@
29092907
<Trigger Property="IsSelected" Value="True">
29102908
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29112909
<Setter Property="Background" Value="{DynamicResource WD.DefaultBackgroundSolidColorBrush}" />
2912-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2910+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29132911
</Trigger>
29142912
<Trigger Property="IsMouseOver" Value="True">
2915-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2913+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29162914
</Trigger>
29172915
</ControlTemplate.Triggers>
29182916
</ControlTemplate>
@@ -2956,7 +2954,7 @@
29562954
<Border x:Name="HeaderBorder" Grid.Row="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,1">
29572955
<TabPanel Name="HeaderPanel" Margin="2,2,2,0" Panel.ZIndex="1" IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
29582956
</Border>
2959-
<controls:SmallPanel Name="ContentPanel" Grid.Row="1" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
2957+
<controls:SmallPanel x:Name="ContentPanel" Grid.Row="1" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
29602958
<ContentPresenter Name="PART_SelectedContentHost" Margin="{TemplateBinding Padding}" Content="{TemplateBinding SelectedContent}" ContentSource="SelectedContent" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" ContentTemplate="{TemplateBinding SelectedContentTemplate}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
29612959
</controls:SmallPanel>
29622960
</Grid>
@@ -5700,7 +5698,7 @@
57005698
<ControlTemplate TargetType="{x:Type controls:StepItem}">
57015699
<StackPanel>
57025700
<controls:SmallPanel>
5703-
<Ellipse Width="45" Height="30" HorizontalAlignment="Center" Fill="{DynamicResource WD.WindowForegroundColorBrush}" />
5701+
<Ellipse Width="45" Height="30" HorizontalAlignment="Center" Fill="{DynamicResource WD.BackgroundSolidColorBrush}" />
57045702
<Border Width="30" Height="30" HorizontalAlignment="Center" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="15">
57055703
<controls:SmallPanel>
57065704
<TextBlock Name="PART_Index" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:StepItem}}, Converter={StaticResource WD.StepIndexConverter}}" />

src/WPFDevelopers.Net45x/Themes/Theme.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@
749749
<Style x:Key="WPFDevelopersWindow" BasedOn="{x:Null}" TargetType="{x:Type wd:Window}">
750750
<Setter Property="Foreground" Value="{DynamicResource WD.RegularTextSolidColorBrush}" />
751751
<Setter Property="Background" Value="{DynamicResource WD.BackgroundSolidColorBrush}" />
752-
<Setter Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
753-
<Setter Property="TitleBackground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
752+
<Setter Property="BorderBrush" Value="{DynamicResource WD.WindowBorderBrushSolidColorBrush}" />
753+
<Setter Property="TitleBackground" Value="{DynamicResource WD.WindowBorderBrushSolidColorBrush}" />
754754
<Setter Property="BorderThickness" Value="1" />
755755
<Setter Property="IsTabStop" Value="False" />
756756
<Setter Property="SnapsToDevicePixels" Value="True" />
@@ -2841,7 +2841,7 @@
28412841
<ScaleTransform ScaleX="0" ScaleY="1" />
28422842
</Border.RenderTransform>
28432843
</Border>
2844-
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2844+
<ContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
28452845
<VisualStateManager.VisualStateGroups>
28462846
<VisualStateGroup x:Name="SelectionStates">
28472847
<VisualState x:Name="Unselected" />
@@ -2862,10 +2862,10 @@
28622862
<Trigger Property="IsSelected" Value="True">
28632863
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28642864
<Setter Property="Background" Value="{DynamicResource WD.DefaultBackgroundSolidColorBrush}" />
2865-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2865+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28662866
</Trigger>
28672867
<Trigger Property="IsMouseOver" Value="True">
2868-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2868+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
28692869
</Trigger>
28702870
</ControlTemplate.Triggers>
28712871
</ControlTemplate>
@@ -2889,7 +2889,7 @@
28892889
<ScaleTransform ScaleX="1" ScaleY="0" />
28902890
</Border.RenderTransform>
28912891
</Border>
2892-
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2892+
<ContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
28932893
<VisualStateManager.VisualStateGroups>
28942894
<VisualStateGroup x:Name="SelectionStates">
28952895
<VisualState x:Name="Unselected" />
@@ -2910,10 +2910,10 @@
29102910
<Trigger Property="IsSelected" Value="True">
29112911
<Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29122912
<Setter Property="Background" Value="{DynamicResource WD.DefaultBackgroundSolidColorBrush}" />
2913-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2913+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29142914
</Trigger>
29152915
<Trigger Property="IsMouseOver" Value="True">
2916-
<Setter Property="Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
2916+
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
29172917
</Trigger>
29182918
</ControlTemplate.Triggers>
29192919
</ControlTemplate>
@@ -2957,7 +2957,7 @@
29572957
<Border x:Name="HeaderBorder" Grid.Row="0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,0,1">
29582958
<TabPanel Name="HeaderPanel" Margin="2,2,2,0" Panel.ZIndex="1" IsItemsHost="True" KeyboardNavigation.TabIndex="1" />
29592959
</Border>
2960-
<controls:SmallPanel Name="ContentPanel" Grid.Row="1" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
2960+
<controls:SmallPanel x:Name="ContentPanel" Grid.Row="1" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
29612961
<ContentPresenter Name="PART_SelectedContentHost" Margin="{TemplateBinding Padding}" Content="{TemplateBinding SelectedContent}" ContentSource="SelectedContent" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" ContentTemplate="{TemplateBinding SelectedContentTemplate}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
29622962
</controls:SmallPanel>
29632963
</Grid>
@@ -5701,7 +5701,7 @@
57015701
<ControlTemplate TargetType="{x:Type controls:StepItem}">
57025702
<StackPanel>
57035703
<controls:SmallPanel>
5704-
<Ellipse Width="45" Height="30" HorizontalAlignment="Center" Fill="{DynamicResource WD.WindowForegroundColorBrush}" />
5704+
<Ellipse Width="45" Height="30" HorizontalAlignment="Center" Fill="{DynamicResource WD.BackgroundSolidColorBrush}" />
57055705
<Border Width="30" Height="30" HorizontalAlignment="Center" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="15">
57065706
<controls:SmallPanel>
57075707
<TextBlock Name="PART_Index" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:StepItem}}, Converter={StaticResource WD.StepIndexConverter}}" />

src/WPFDevelopers.Samples.Shared/ExampleViews/CropImageExample.xaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,47 @@
1313
<controls:CodeViewer>
1414
<Grid>
1515
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto" />
1617
<RowDefinition Height="*" />
1718
<RowDefinition Height="Auto" />
1819
</Grid.RowDefinitions>
1920
<Grid.ColumnDefinitions>
2021
<ColumnDefinition />
2122
<ColumnDefinition />
2223
</Grid.ColumnDefinitions>
24+
<WrapPanel>
25+
<CheckBox
26+
x:Name="myCheckBox"
27+
Content="开启等比缩放"
28+
IsChecked="False" />
29+
<StackPanel Orientation="Horizontal">
30+
<TextBlock Text="裁剪区域比例:" />
31+
<Slider
32+
x:Name="myRectScaleSlider"
33+
Width="100"
34+
Maximum="1"
35+
Minimum="0"
36+
Value="0.5" />
37+
</StackPanel>
38+
39+
</WrapPanel>
2340
<wd:CropImage
2441
Name="MyCropImage"
25-
Grid.Row="0"
26-
Grid.Column="0" />
42+
Grid.Row="1"
43+
Grid.Column="0"
44+
IsRatioScale="{Binding ElementName=myCheckBox, Path=IsChecked}"
45+
RectScale="{Binding ElementName=myRectScaleSlider, Path=Value}"
46+
ScaleSize="2.35,1" />
2747
<Image
48+
Grid.Row="1"
2849
Grid.Column="1"
2950
Width="{Binding CurrentRect.Width, ElementName=MyCropImage}"
3051
Height="{Binding CurrentRect.Height, ElementName=MyCropImage}"
3152
VerticalAlignment="Center"
3253
Source="{Binding CurrentAreaBitmap, ElementName=MyCropImage}"
3354
Stretch="Uniform" />
3455
<StackPanel
35-
Grid.Row="1"
56+
Grid.Row="2"
3657
Grid.ColumnSpan="2"
3758
HorizontalAlignment="Center"
3859
Orientation="Horizontal">

0 commit comments

Comments
 (0)