提交记录修改UI/Controls/Charts/Charts.cs+111 −24看文件
修改UI/Controls/Charts/ChartsItemTypeA.cs+13 −2看文件
修改UI/Themes/Charts/Charts.xaml+5 −4看文件
修改UI/Themes/Charts/ChartsItemTypeA.xaml+40 −9看文件
| @@ -13,6 +13,7 @@ using System.Windows.Media; | ||
| 13 | 13 | using System.Windows.Media.Imaging; |
| 14 | 14 | using System.Windows.Navigation; |
| 15 | 15 | using System.Windows.Shapes; |
| 16 | 新增:using System.Windows.Threading; | |
| 16 | 17 | using UI.Controls.Base; |
| 17 | 18 | using UI.Controls.Charts.Model; |
| 18 | 19 | using UI.Extensions; |
| @@ -142,9 +143,8 @@ namespace UI.Controls.Charts | ||
| 142 | 143 | private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 143 | 144 | { |
| 144 | 145 | var charts = (d as Charts); |
| 145 | 删除: if (e.Property == DataProperty) | |
| 146 | 新增: if (e.Property == DataProperty && e.OldValue != e.NewValue) | |
| 146 | 147 | { |
| 147 | 删除: var dc = charts.ChartsType; | |
| 148 | 148 | charts.Render(); |
| 149 | 149 | } |
| 150 | 150 | if (e.Property == IsLoadingProperty) |
| @@ -171,7 +171,7 @@ namespace UI.Controls.Charts | ||
| 171 | 171 | private StackPanel Container; |
| 172 | 172 | private WrapPanel CardContainer; |
| 173 | 173 | private Grid MonthContainer; |
| 174 | 删除: | |
| 174 | 新增: private ScrollViewer ScrollViewer; | |
| 175 | 175 | /// <summary> |
| 176 | 176 | /// 是否在渲染中 |
| 177 | 177 | /// </summary> |
| @@ -180,6 +180,19 @@ namespace UI.Controls.Charts | ||
| 180 | 180 | /// 计算最大值 |
| 181 | 181 | /// </summary> |
| 182 | 182 | private double maxValue = 0; |
| 183 | 新增: /// <summary> | |
| 184 | 新增: /// 是否启用懒加载 | |
| 185 | 新增: /// </summary> | |
| 186 | 新增: private bool isLazyloading = false; | |
| 187 | 新增: /// <summary> | |
| 188 | 新增: /// 项目真实高度 | |
| 189 | 新增: /// </summary> | |
| 190 | 新增: private double itemHeight = 0; | |
| 191 | 新增: /// <summary> | |
| 192 | 新增: /// 懒加载完成条数 | |
| 193 | 新增: /// </summary> | |
| 194 | 新增: private int lazyloadedCount = 0; | |
| 195 | 新增: private List<ChartsDataModel> lazyloadingData; | |
| 183 | 196 | public Charts() |
| 184 | 197 | { |
| 185 | 198 | DefaultStyleKey = typeof(Charts); |
| @@ -190,22 +203,15 @@ namespace UI.Controls.Charts | ||
| 190 | 203 | Container = GetTemplateChild("Container") as StackPanel; |
| 191 | 204 | CardContainer = GetTemplateChild("CardContainer") as WrapPanel; |
| 192 | 205 | MonthContainer = GetTemplateChild("MonthContainer") as Grid; |
| 206 | 新增: ScrollViewer = GetTemplateChild("ScrollViewer") as ScrollViewer; | |
| 193 | 207 | |
| 194 | 删除: Loaded += Charts_Loaded; | |
| 195 | 删除: } | |
| 196 | 删除: | |
| 197 | 删除: private void Charts_Loaded(object sender, RoutedEventArgs e) | |
| 198 | 删除: { | |
| 199 | 删除: if (Container != null) | |
| 208 | 新增: if (IsLoading) | |
| 200 | 209 | { |
| 201 | 删除: if (IsLoading) | |
| 202 | 删除: { | |
| 203 | 删除: RenderLoadingPlaceholder(); | |
| 204 | 删除: } | |
| 205 | 删除: else | |
| 206 | 删除: { | |
| 207 | 删除: Render(); | |
| 208 | 删除: } | |
| 210 | 新增: RenderLoadingPlaceholder(); | |
| 211 | 新增: } | |
| 212 | 新增: else | |
| 213 | 新增: { | |
| 214 | 新增: Render(); | |
| 209 | 215 | } |
| 210 | 216 | } |
| 211 | 217 | |
| @@ -276,7 +282,6 @@ namespace UI.Controls.Charts | ||
| 276 | 282 | } |
| 277 | 283 | |
| 278 | 284 | isRendering = true; |
| 279 | 删除: | |
| 280 | 285 | switch (ChartsType) |
| 281 | 286 | { |
| 282 | 287 | case ChartsType.HorizontalA: |
| @@ -289,31 +294,113 @@ namespace UI.Controls.Charts | ||
| 289 | 294 | RenderMonthStyle(); |
| 290 | 295 | break; |
| 291 | 296 | } |
| 292 | 删除: } | |
| 293 | 297 | |
| 298 | 新增: } | |
| 299 | 新增: | |
| 294 | 300 | #region 渲染横向样式A |
| 295 | 301 | private void RenderHorizontalAStyle() |
| 296 | 302 | { |
| 297 | 删除: | |
| 303 | 新增: lazyloadingData = null; | |
| 304 | 新增: isLazyloading = false; | |
| 305 | 新增: lazyloadedCount = 0; | |
| 306 | 新增: ScrollViewer.ScrollToVerticalOffset(0); | |
| 307 | 新增: | |
| 298 | 308 | var data = Data.OrderByDescending(x => x.Value).ToList(); |
| 299 | 309 | |
| 300 | 删除: foreach (var item in data) | |
| 310 | 新增: if (data.Count < 20) | |
| 311 | 新增: { | |
| 312 | 新增: RenderTypeAItems(data, 0, data.Count); | |
| 313 | 新增: } | |
| 314 | 新增: else | |
| 315 | 新增: { | |
| 316 | 新增: isLazyloading = true; | |
| 317 | 新增: RenderTypeAItems(data, 0, 20); | |
| 318 | 新增: lazyloadingData = data; | |
| 319 | 新增: ScrollViewer.ScrollChanged += ScrollViewer_ScrollChanged; | |
| 320 | 新增: } | |
| 321 | 新增: Container.SizeChanged -= Container_SizeChanged; | |
| 322 | 新增: Container.SizeChanged += Container_SizeChanged; | |
| 323 | 新增: isRendering = false; | |
| 324 | 新增: } | |
| 325 | 新增: | |
| 326 | 新增: private void Container_SizeChanged(object sender, SizeChangedEventArgs e) | |
| 327 | 新增: { | |
| 328 | 新增: foreach (var item in Container.Children) | |
| 329 | 新增: { | |
| 330 | 新增: var control = item as ChartsItemTypeA; | |
| 331 | 新增: if (control != null) | |
| 332 | 新增: { | |
| 333 | 新增: control.UpdateValueBlockWidth(); | |
| 334 | 新增: } | |
| 335 | 新增: } | |
| 336 | 新增: } | |
| 337 | 新增: | |
| 338 | 新增: private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) | |
| 339 | 新增: { | |
| 340 | 新增: if (ScrollViewer.VerticalOffset > 0 && e.VerticalChange > 0) | |
| 301 | 341 | { |
| 342 | 新增: double a = ScrollViewer.VerticalOffset * itemHeight; | |
| 343 | 新增: double b = itemHeight * lazyloadedCount; | |
| 344 | 新增: if (b - a <= ScrollViewer.ActualHeight) | |
| 345 | 新增: { | |
| 346 | 新增: RenderTypeAItems(lazyloadingData, lazyloadedCount, 20); | |
| 347 | 新增: } | |
| 348 | 新增: } | |
| 349 | 新增: | |
| 350 | 新增: if (lazyloadedCount == Data.Count()) | |
| 351 | 新增: { | |
| 352 | 新增: ScrollViewer.ScrollChanged -= ScrollViewer_ScrollChanged; | |
| 353 | 新增: } | |
| 354 | 新增: } | |
| 355 | 新增: | |
| 356 | 新增: private void RenderTypeAItems(List<ChartsDataModel> data, int start, int count) | |
| 357 | 新增: { | |
| 358 | 新增: for (int i = start; i < start + count; i++) | |
| 359 | 新增: { | |
| 360 | 新增: | |
| 361 | 新增: if (i >= data.Count) | |
| 362 | 新增: { | |
| 363 | 新增: break; | |
| 364 | 新增: } | |
| 365 | 新增: ChartsDataModel item = data[i]; | |
| 302 | 366 | var chartsItem = new ChartsItemTypeA(); |
| 303 | 367 | chartsItem.Data = item; |
| 304 | 368 | chartsItem.ToolTip = item.PopupText; |
| 305 | 369 | chartsItem.MaxValue = maxValue; |
| 306 | 删除: | |
| 370 | 新增: if (i == 19 && isLazyloading) | |
| 371 | 新增: { | |
| 372 | 新增: chartsItem.Loaded += ChartsItem_Loaded; | |
| 373 | 新增: } | |
| 307 | 374 | // 处理点击事件 |
| 308 | 375 | HandleItemClick(chartsItem, item); |
| 376 | 新增: Container.Children.Insert(lazyloadedCount, chartsItem); | |
| 309 | 377 | |
| 310 | 删除: Container.Children.Add(chartsItem); | |
| 311 | 378 | if (ShowLimit > 0 && Container.Children.Count == ShowLimit) |
| 312 | 379 | { |
| 313 | 380 | break; |
| 314 | 381 | } |
| 382 | 新增: lazyloadedCount++; | |
| 383 | 新增: if (i >= 20) | |
| 384 | 新增: { | |
| 385 | 新增: Container.Children.RemoveAt(Container.Children.Count - 1); | |
| 386 | 新增: } | |
| 315 | 387 | } |
| 316 | 删除: isRendering = false; | |
| 388 | 新增: } | |
| 389 | 新增: | |
| 390 | 新增: private void ChartsItem_Loaded(object sender, RoutedEventArgs e) | |
| 391 | 新增: { | |
| 392 | 新增: var chartsItem = (ChartsItemTypeA)sender; | |
| 393 | 新增: chartsItem.Loaded -= ChartsItem_Loaded; | |
| 394 | 新增: | |
| 395 | 新增: int count = Data.Count() - 20; | |
| 396 | 新增: for (int i = 0; i < count; i++) | |
| 397 | 新增: { | |
| 398 | 新增: var pl = new TextBlock(); | |
| 399 | 新增: pl.Height = chartsItem.ActualHeight; | |
| 400 | 新增: Container.Children.Add(pl); | |
| 401 | 新增: } | |
| 402 | 新增: | |
| 403 | 新增: itemHeight = chartsItem.ActualHeight; | |
| 317 | 404 | } |
| 318 | 405 | #endregion |
| 319 | 406 | #region 渲染卡片样式Card |
| @@ -73,6 +73,7 @@ namespace UI.Controls.Charts | ||
| 73 | 73 | private TextBlock NameTextObj, ValueTextObj; |
| 74 | 74 | private Rectangle ValueBlockObj; |
| 75 | 75 | private StackPanel ValueContainer; |
| 76 | 新增: //private Grid ValueContainer; | |
| 76 | 77 | private Image IconObj; |
| 77 | 78 | private bool isRendering = false; |
| 78 | 79 | public ChartsItemTypeA() |
| @@ -85,6 +86,7 @@ namespace UI.Controls.Charts | ||
| 85 | 86 | NameTextObj = GetTemplateChild("NameTextObj") as TextBlock; |
| 86 | 87 | ValueTextObj = GetTemplateChild("ValueTextObj") as TextBlock; |
| 87 | 88 | ValueBlockObj = GetTemplateChild("ValueBlockObj") as Rectangle; |
| 89 | 新增: //ValueContainer = GetTemplateChild("ValueContainer") as Grid; | |
| 88 | 90 | ValueContainer = GetTemplateChild("ValueContainer") as StackPanel; |
| 89 | 91 | |
| 90 | 92 | IconObj = GetTemplateChild("IconObj") as Image; |
| @@ -99,7 +101,7 @@ namespace UI.Controls.Charts | ||
| 99 | 101 | |
| 100 | 102 | private void Render() |
| 101 | 103 | { |
| 102 | 删除: if (isRendering || Data==null) | |
| 104 | 新增: if (isRendering || Data == null) | |
| 103 | 105 | { |
| 104 | 106 | return; |
| 105 | 107 | } |
| @@ -114,10 +116,19 @@ namespace UI.Controls.Charts | ||
| 114 | 116 | { |
| 115 | 117 | return; |
| 116 | 118 | } |
| 117 | 删除: ValueBlockObj.Width = (Data.Value / MaxValue) * (ValueContainer.ActualWidth * 0.95 - ValueTextObj.ActualWidth); | |
| 119 | 新增: UpdateValueBlockWidth(); | |
| 118 | 120 | }; |
| 119 | 121 | } |
| 120 | 122 | |
| 123 | 新增: public void UpdateValueBlockWidth() | |
| 124 | 新增: { | |
| 125 | 新增: if (Data == null) | |
| 126 | 新增: { | |
| 127 | 新增: return; | |
| 128 | 新增: } | |
| 129 | 新增: ValueBlockObj.Width = (Data.Value / MaxValue) * (ValueContainer.ActualWidth * 0.95 - ValueTextObj.ActualWidth); | |
| 130 | 新增: } | |
| 131 | 新增: | |
| 121 | 132 | protected override void OnMouseEnter(MouseEventArgs e) |
| 122 | 133 | { |
| 123 | 134 | base.OnMouseEnter(e); |
| @@ -5,7 +5,6 @@ | ||
| 5 | 5 | <Setter Property="SnapsToDevicePixels" |
| 6 | 6 | Value="true" /> |
| 7 | 7 | |
| 8 | 删除: | |
| 9 | 8 | <Setter Property="FontSize" Value="14"/> |
| 10 | 9 | <Setter Property="Background" Value="Transparent"/> |
| 11 | 10 | |
| @@ -14,9 +13,11 @@ | ||
| 14 | 13 | <ControlTemplate TargetType="{x:Type local:Charts}"> |
| 15 | 14 | <Border Background="{TemplateBinding Background}"> |
| 16 | 15 | <Grid> |
| 17 | 删除: <Grid x:Name="HorizontalA" Visibility="Collapsed"> | |
| 18 | 删除: <StackPanel x:Name="Container"> | |
| 19 | 删除: </StackPanel> | |
| 16 | 新增: <Grid x:Name="HorizontalA" Visibility="Collapsed"> | |
| 17 | 新增: <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Auto" Height="{Binding ElementName=HorizontalA,Path=ActualHeight}" CanContentScroll="True"> | |
| 18 | 新增: <StackPanel x:Name="Container"> | |
| 19 | 新增: </StackPanel> | |
| 20 | 新增: </ScrollViewer> | |
| 20 | 21 | </Grid> |
| 21 | 22 | <Grid x:Name="Card" Visibility="Collapsed"> |
| 22 | 23 | <WrapPanel x:Name="CardContainer"> |
| @@ -20,11 +20,37 @@ | ||
| 20 | 20 | <ColumnDefinition Width="*"/> |
| 21 | 21 | </Grid.ColumnDefinitions> |
| 22 | 22 | <Grid Margin="0,0,10,0"> |
| 23 | 删除: <Border Background="#f3f3f3" CornerRadius="6" Width="50" Height="50" HorizontalAlignment="Left"> | |
| 23 | 新增: <Border x:Name="IconBorder" BorderBrush="Transparent" BorderThickness="2" Background="#f3f3f3" CornerRadius="6" Width="50" Height="50" HorizontalAlignment="Left"> | |
| 24 | 24 | <Image x:Name="IconObj" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/> |
| 25 | 25 | </Border> |
| 26 | 26 | </Grid> |
| 27 | 删除: <StackPanel Grid.Column="1" x:Name="ValueContainer" VerticalAlignment="Center" > | |
| 27 | 新增: <!--<Grid Grid.Column="1" x:Name="ValueContainer" VerticalAlignment="Center" > | |
| 28 | 新增: <Grid.RowDefinitions> | |
| 29 | 新增: <RowDefinition Height="*"/> | |
| 30 | 新增: <RowDefinition Height="*"/> | |
| 31 | 新增: | |
| 32 | 新增: </Grid.RowDefinitions> | |
| 33 | 新增: <TextBlock x:Name="NameTextObj" Foreground="#5c5c5c" HorizontalAlignment="Left"/> | |
| 34 | 新增: <Grid Grid.Row="1" > | |
| 35 | 新增: <Grid.ColumnDefinitions> | |
| 36 | 新增: <ColumnDefinition Width="auto"/> | |
| 37 | 新增: <ColumnDefinition Width="auto"/> | |
| 38 | 新增: | |
| 39 | 新增: </Grid.ColumnDefinitions> | |
| 40 | 新增: <Rectangle | |
| 41 | 新增: x:Name="ValueBlockObj" | |
| 42 | 新增: RadiusX="4" | |
| 43 | 新增: RadiusY="4" | |
| 44 | 新增: Fill="#cccccc" | |
| 45 | 新增: Height="8" | |
| 46 | 新增: VerticalAlignment="Center" | |
| 47 | 新增: HorizontalAlignment="Left" | |
| 48 | 新增: /> | |
| 49 | 新增: | |
| 50 | 新增: <TextBlock Grid.Column="1" x:Name="ValueTextObj" VerticalAlignment="Center" Foreground="#5c5c5c" FontSize="12" Margin="5,0,0,0"/> | |
| 51 | 新增: </Grid> | |
| 52 | 新增: </Grid>--> | |
| 53 | 新增: <StackPanel Grid.Column="1" x:Name="ValueContainer" VerticalAlignment="Center" > | |
| 28 | 54 | <TextBlock x:Name="NameTextObj" Foreground="#5c5c5c" HorizontalAlignment="Left"/> |
| 29 | 55 | <StackPanel Orientation="Horizontal" > |
| 30 | 56 | <Rectangle |
| @@ -88,13 +114,18 @@ | ||
| 88 | 114 | <CubicEase EasingMode="EaseInOut"/> |
| 89 | 115 | </ColorAnimation.EasingFunction> |
| 90 | 116 | </ColorAnimation> |
| 91 | 删除: <!--<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" | |
| 92 | 删除: Storyboard.TargetName="Bg" > | |
| 93 | 删除: <EasingColorKeyFrame KeyTime="0" | |
| 94 | 删除: Value="#192B20D9"/> | |
| 95 | 删除: | |
| 96 | 删除: </ColorAnimationUsingKeyFrames>--> | |
| 97 | 删除: | |
| 117 | 新增: <ColorAnimation Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" | |
| 118 | 新增: Storyboard.TargetName="IconBorder" To="#2b20d9" > | |
| 119 | 新增: <ColorAnimation.EasingFunction> | |
| 120 | 新增: <CubicEase EasingMode="EaseInOut"/> | |
| 121 | 新增: </ColorAnimation.EasingFunction> | |
| 122 | 新增: </ColorAnimation> | |
| 123 | 新增: <ColorAnimation Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" | |
| 124 | 新增: Storyboard.TargetName="IconBorder" To="#ffffff" > | |
| 125 | 新增: <ColorAnimation.EasingFunction> | |
| 126 | 新增: <CubicEase EasingMode="EaseInOut"/> | |
| 127 | 新增: </ColorAnimation.EasingFunction> | |
| 128 | 新增: </ColorAnimation> | |
| 98 | 129 | </Storyboard> |
| 99 | 130 | </VisualState> |
| 100 | 131 | <VisualState x:Name="Pressed"> |

