Browse Source

compdfkit(win) - 修复HomePage滚动问题

liuaoran 1 năm trước cách đây
mục cha
commit
7304f812ab

+ 31 - 0
Demo/Examples/Compdfkit_Tools/Common/Convert/HomePageFileListHeightConverter.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace Compdfkit_Tools.Common
+{
+    public class HomePageFileListHeightConverter : IMultiValueConverter
+    {
+        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (values[0] == null || values[1] == null)
+            {
+                return false;
+            }
+            else
+            {
+                var value = (double)values[0] - (double)values[1] - 32;
+                return (value >= 200.0) ? value : 200.0;
+            }
+        }
+
+        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+        {
+            return null;
+        }
+    }
+}

+ 17 - 7
Demo/Examples/Compdfkit_Tools/Common/HomePage/HomePageControl.xaml

@@ -5,9 +5,10 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
              mc:Ignorable="d" 
-             d:DesignHeight="1040" d:DesignWidth="1920"
+               xmlns:common="clr-namespace:Compdfkit_Tools.Common"
+             d:DesignHeight="800" d:DesignWidth="1920"
              Loaded="UserControl_Loaded"
-             Unloaded="UserControl_Unloaded">
+             Unloaded="UserControl_Unloaded" x:Name="HomePage">
     <UserControl.Resources>
         <DrawingImage x:Key="OpenDocumentIcon">
             <DrawingImage.Drawing>
@@ -54,7 +55,7 @@
                 </Setter.Value>
             </Setter>
         </Style>
-
+        <common:HomePageFileListHeightConverter x:Key="HomePageFileListHeightConverter"></common:HomePageFileListHeightConverter>
     </UserControl.Resources>
     <Grid>
         <Grid.ColumnDefinitions>
@@ -77,13 +78,22 @@
                     </StackPanel>
                 </Button>
             </StackPanel>
-            <Grid Grid.Column="1" Background="#F2F2F2">
+        <ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto" IsTabStop="True">
+            <Grid x:Name="HomeGrid" Background="#F2F2F2">
                 <Grid.RowDefinitions>
-                    <RowDefinition MinHeight="640"></RowDefinition>
-                    <RowDefinition MinHeight="200"></RowDefinition>
+                    <RowDefinition Height="580" ></RowDefinition>
+                    <RowDefinition> </RowDefinition>
                 </Grid.RowDefinitions>
                 <local:FeaturesListControl x:Name="FeaturesListControl"></local:FeaturesListControl>
-                <local:RecentFilesControl Grid.Row="1" x:Name="RecentFilesControl" Margin="0,20,0,0"></local:RecentFilesControl>
+                <local:RecentFilesControl Grid.Row="1" x:Name="RecentFilesControl" Margin="0,20,0,0" >
+                    <local:RecentFilesControl.Height>
+                        <MultiBinding Converter="{StaticResource HomePageFileListHeightConverter}">
+                            <Binding ElementName="HomePage" Path="ActualHeight"></Binding>
+                            <Binding ElementName="FeaturesListControl" Path="ActualHeight"></Binding>
+                        </MultiBinding>
+                    </local:RecentFilesControl.Height>
+                </local:RecentFilesControl>
             </Grid>
+        </ScrollViewer>
     </Grid>
 </UserControl>

+ 14 - 1
Demo/Examples/Compdfkit_Tools/Common/HomePage/HomePageControl.xaml.cs

@@ -35,7 +35,7 @@ namespace Compdfkit_Tools.PDFControl
         Canvas waterCanvas = new Canvas();
 
         private List<CustomItem> customItems;
-        
+
         /// <summary>
         /// Open file event. 
         /// param: Whether to create a file
@@ -103,6 +103,19 @@ namespace Compdfkit_Tools.PDFControl
             CreateCustomItems();
 
             ImportFeatures();
+
+            UseTheScrollViewerScrolling(FeaturesListControl);
+        }
+
+        private void UseTheScrollViewerScrolling(FrameworkElement fElement)
+        {
+            fElement.PreviewMouseWheel += (sender, e) =>
+              {
+                  var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
+                  eventArg.RoutedEvent = UIElement.MouseWheelEvent;
+                  eventArg.Source = sender;
+                  fElement.RaiseEvent(eventArg);
+              };
         }
 
         private void CreateCustomItems()

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Common/HomePage/RecentFilesControl.xaml

@@ -83,7 +83,7 @@
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         <TextBlock Text="Quick Start" Background="Transparent" Margin="0,0,0,25" Height="32" FontFamily="Segoe UI" FontSize="24" LineHeight="32" Foreground="#001A4E"></TextBlock>
-        <ListView Grid.Row="1" x:Name="HistoryListView" MinWidth="380" MinHeight="216" 
+        <ListView Grid.Row="1" x:Name="HistoryListView" MinWidth="380"
                   ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                   Style="{StaticResource HistoryListBoxStyle}" ItemsSource="{Binding History}" 
                   ItemContainerStyle="{StaticResource ItemContainerStyle}"

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Compdfkit_Tools.csproj

@@ -131,6 +131,7 @@
     </Compile>
     <Compile Include="Common\Convert\BoolToColorConverter.cs" />
     <Compile Include="Common\Convert\HeightToTopMarginConverter.cs" />
+    <Compile Include="Common\Convert\HomePageFileListHeightConverter.cs" />
     <Compile Include="Common\Convert\HomePageHeightConverter.cs" />
     <Compile Include="Common\Convert\AndMultiBoolValueConverter.cs" />
     <Compile Include="Common\Convert\AnnotArgsTypeToVisibilityConverter.cs" />