惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Security Latest
Security Latest
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
L
LINUX DO - 最新话题
美团技术团队
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
C
Cisco Blogs
G
Google Developers Blog
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
Y
Y Combinator Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
博客园 - Franky
雷峰网
雷峰网
N
News and Events Feed by Topic
B
Blog
J
Java Code Geeks
Project Zero
Project Zero
人人都是产品经理
人人都是产品经理
W
WeLiveSecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Webroot Blog
Webroot Blog
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
宝玉的分享
宝玉的分享
P
Privacy International News Feed
Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hacker News: Ask HN
Hacker News: Ask HN

博客园 - FredGrit

WPF two separated datagrid scroll synchronously both in horizontal and vertical via behavior WPF ContentControl Template is ControlTemplate, ContentTemplate is DataTemplate and must assign value to Content explicitly WPF TreeView show WCF config file WPF itemscontrol loaded downloaded data from WCF via httpclient WPF consume xml generated by WCF , C# deserialize xml to List WPF implemented ICommand and IDisposable WPF ContextMenu,MenuItem command can binding to datacontext's command directly WPF usercontrol pass contextmenu command via implemented Freezable class which does not attach on Visual tree, then invoked in caller MVVM WPF consume data generate by WCF and save via ContextMenu Command in MVVM C# export List<T> to excel file via EPPlus WPF ContextMenu does not rely on host visual tree, the Freezable can exist independently, convey dependency property in usercontrol to caller C# JsonConvert DeserializeObject MissingMemberHandling.Ignore when the source model is completed and the required is partial Freezable objects do not require attachment to the WPF visual tree, maintain a persistent lifetime, and serve as a reliable binding relay between a detached ContextMenu and its parent host control. C# run httplistener to act as service application asynchronously in console, semaphoreslim allow the max concurrent number WPF Microsoft.Xaml.Behaviors.WPF, EventTrigger EventName="PreviewMouseDown" the tunnel event, while the MouseDown can't trigger the command because it was swallowed WPF customize command implemented ICommand, volatile read method is thread safe, preventing cpu and comipler reorder and optimization. WPF ItemsControl load huge 50M+ data WPF consume data generated by WCF periodically in json format WPF customize command based on ICommand and manually trigger WPF consume data generated by grpc services C# produce and consume data via Google.Protobuf WCF produce message and WPF consume periodically via DispatcherTimer WCF deconstruct WebConfig includes bindings, behaviors, service, endpoint ,serviceHostingEnvironment C# insert data into SQLite in batch periodically WPF SQLite SQLiteStudio WPF customize MultiSelectComboBox based on combobox WPF DataGrid Context menu binding command and commandparameter to datacontext WCF set fixed port as http://localhost:8888/ via Project /Properties/web/project url to create virtual directory WPF customize datagrid behavior based on behavior&lt;datagrid&gt; with command and command parameter WPF Microsoft Visual Studio XAML designer is busy WCF WebHttpBinding support both http and https WCF support basicHttpBinding and webHttpBinding - FredGrit WCF TestClient set fixed configuration file WPF consume http json and update periodically via DispatcherTimer WPF Prism.Core version 9.0.537 implemented navigation register singleton with splash screen, pass global variable via RegisterSingleton method WPF render periodically via DispatcherTimer, customize behavior - FredGrit Python cosume WCF service via requests in json format WPF call webHttpBinding from WCF WCF binding webHttpBinding is used to web browser in json format both in request and response WPF invoke WCF dll periodically via DispatcherTimer WCF webHttpBinding is open for web browser and wpf WPF DataTemplateSelector WPF DataGrid customize behavior with multiple commands and command parameters then invoke in mvvm WPF DataGrid behavior customize command and command parameter then invoke and implemented in MVVM WPF ItemsControl customize behavior and save all items WCF service can be accessed by browser WPF WCF produce data as service and WPF consume data as client periodically WPF GRPC and Probuf generated data as service then consume by wpf periodically WPF customize behavior based on Microsoft.Xaml.Behaviors.Wpf with command and commandparameter WPF call data from CPP wrapper dll via CLI\CLR - FredGrit WPF customize behavior WPF get gpu information via System.Management WPF ItemsControl IsItemsHost=True WPF Customize behavior and dependency property command C# Serilog, Serilog.Sinks.Console, Serilog.Sinks.File C# Serilog both in file and console Windows powershell view huge file via command C# serialize huge data more than 100M via splitting into batch and concatenating as one big json file WPF WeakReference C# serialize datetime then deserialize, print lose precision. resolve by ToString(&quot;o&quot;) C# produce data and send via WebSocket as service, Python,Flask,HTML as consumer invoke periodically C# write generated data service and sent via websocket, then consume by python periodically C# DateTime print precision to microseconds C# WebSocket console as service provide data, another console as client,send request periodically C# WebAPI [HttpGet(&quot;{cnt}&quot;] pass argument WPF implement ICommand with async execute WPF ListBox control virtualization in mvvm WPF Data Source invoke from web api C# WebAPI
WPF TreeView HierarchicalDataTemplate DataTemplate, Enum get enum name
FredGrit · 2026-07-05 · via 博客园 - FredGrit
public enum BookCategory
{
    Science,
    Technology,
    Engineer,
    Math,
    Arts
}

static Array values = Enum.GetValues(typeof(BookCategory));
static Random rnd = new Random();

int rndIdx = rnd.Next(0, values.Length);
string categoryName = Enum.GetName(typeof(BookCategory), rndIdx);
BookCategoryName = categoryName
Install-Package CommunityToolkit.mvvm
Install-Package Newtonsoft.json
<Window x:Class="WpfApp13.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp13"
        mc:Ignorable="d"
        Title="MainWindow" WindowState="Maximized">

    <Window.DataContext>
        <local:MainVM/>
    </Window.DataContext>
    <Window.Resources>
        <local:LenConverter x:Key="LenConverter"/>
        
        <HierarchicalDataTemplate DataType="{x:Type local:CategoryNode}"
                                  ItemsSource="{Binding Books}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding CategoryName}" FontWeight="Bold"
                               FontSize="30">
                </TextBlock>
                <TextBlock Text="(" Margin="5,0,0,0" Foreground="Gray"/>
                <TextBlock Text="{Binding BookCount}" Foreground="Gray"/>
                <TextBlock Text=")" Foreground="Gray"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <DataTemplate DataType="{x:Type local:Book}">
            <Border BorderBrush="LightBlue" BorderThickness="5" Margin="2,2,2,2"
                        Width="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth},
                    Converter={StaticResource LenConverter},ConverterParameter=100}"
                        Height="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight},
                    Converter={StaticResource LenConverter},ConverterParameter=2}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Grid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="FontSize" Value="30"/>
                            <Setter Property="Foreground" Value="Black"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="FontSize" Value="50"/>
                                    <Setter Property="Foreground" Value="Red"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Resources>
                    <TextBlock Text="Id:" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Id}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Name:" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Name}" Grid.Row="0" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="ISBN:" Grid.Row="0" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding ISBN}" Grid.Row="0" Grid.Column="5" HorizontalAlignment="Left"/>
                    <TextBlock Text="Author:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Author}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Comment:" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Comment}" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="Content:" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Content}"  Grid.Row="1" Grid.Column="5" HorizontalAlignment="Left"/>
                    <TextBlock Text="Summary:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Summary}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Title:" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Title}" Grid.Row="2" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="Title:" Grid.Row="2" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Topic}" Grid.Row="2" Grid.Column="5" HorizontalAlignment="Left"/>
                </Grid>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <TreeView ItemsSource="{Binding CategoryNodes}"
                  BorderThickness="1"
                  BorderBrush="LightGray"
                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                  ScrollViewer.VerticalScrollBarVisibility="Auto">
            <TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter Property="IsExpanded" Value="False"/>
                    <Setter Property="FontSize" Value="20"/>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    </Grid>
</Window>

WCF generate data as service

//D:\C\WcfService6\WcfService6\IBookService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService6
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IBookService" in both code and config file together.
    [ServiceContract]
    public interface IBookService
    {
        [OperationContract]
        [WebGet(UriTemplate="/getbookslist?cnt={cnt}",RequestFormat =WebMessageFormat.Json,
            ResponseFormat =WebMessageFormat.Json)]
        List<Book> GetBooksList(long cnt);
    }

    public class Book
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public string BookCategoryName { get; set; }
        public string ISBN { get; set; }
        public string Author { get; set; }
        public string Comment { get; set; }
        public string Content { get; set; }
        public string Summary { get; set; }
        public string Title { get; set; }
        public string Topic { get; set; }
        
    }

    public enum BookCategory
    {
        Science,
        Technology,
        Engineer,
        Math,
        Arts
    }
}


//D:\C\WcfService6\WcfService6\BookService.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;

namespace WcfService6
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "BookService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select BookService.svc or BookService.svc.cs at the Solution Explorer and start debugging.
    public class BookService : IBookService
    {
        private static long id = 1;
        static Random rnd = new Random();
        static Array values = Enum.GetValues(typeof(BookCategory));
        private static (long,long) GetStartEnd(long cnt)
        {
            long end=Interlocked.Add(ref id, cnt);
            long start = end - cnt;
            return (start,end);
        }
        
        public List<Book> GetBooksList(long cnt)
        {
            var (start, end) = GetStartEnd(cnt);
            List<Book> bksList = new List<Book>();
            for(long i=start;i<end;i++)
            {
                int rndIdx = rnd.Next(0, values.Length);
                string categoryName = Enum.GetName(typeof(BookCategory), rndIdx);
                bksList.Add(new Book()
                {
                    Id = i,
                    Name = $"Name_{i}",
                    ISBN = $"ISBN_{i}_{Guid.NewGuid():N}",
                    Author = $"Author_{i}",
                    Comment = $"Comment_{i}",
                    Content = $"Content_{i}",
                    Summary = $"Summary_{i}",
                    Title = $"Title_{i}",
                    Topic = $"Topic_{i}",
                    BookCategoryName = categoryName
                });
            }
            return bksList;
        }
    }
}

//D:\C\WcfService6\WcfService6\Web.config
<?xml version="1.0"?>
<configuration>

    <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.8" />
        <httpRuntime targetFramework="4.8"/>
    </system.web>
    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="BookServiceWebHttpBinding"
                         openTimeout="01:00:00"
                         closeTimeout="01:00:00"
                          receiveTimeout="01:00:00"
                          sendTimeout="01:00:00"
                          maxBufferPoolSize="2147483647"
                          maxBufferSize="2147483647"
                          maxReceivedMessageSize="2147483647">
                    <readerQuotas maxArrayLength="2147483647"
                                   maxBytesPerRead="2147483647"
                                   maxDepth="2147483647"
                                   maxNameTableCharCount="2147483647"
                                   maxStringContentLength="2147483647"/>
                </binding>
            </webHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BookServiceBehavior">
                    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="BookServiceEndpointBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <services>
            <service name="WcfService6.BookService"
                     behaviorConfiguration="BookServiceBehavior">
                <endpoint address=""
                          binding="webHttpBinding"
                          contract="WcfService6.IBookService"
                          bindingName="BookServiceWebHttpBinding"
                          behaviorConfiguration="BookServiceEndpointBehavior"/>                          
            </service>
        </services>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
        <directoryBrowse enabled="true"/>
    </system.webServer>

</configuration>
http://localhost:51906/BookService.svc/getbookslist?cnt=1000

image

//WPF

//D:\C\WpfApp13\WpfApp13\MainWindow.xaml
<Window x:Class="WpfApp13.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp13"
        mc:Ignorable="d"
        Title="MainWindow" WindowState="Maximized">

    <Window.DataContext>
        <local:MainVM/>
    </Window.DataContext>
    <Window.Resources>
        <local:LenConverter x:Key="LenConverter"/>
        
        <HierarchicalDataTemplate DataType="{x:Type local:CategoryNode}"
                                  ItemsSource="{Binding Books}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding CategoryName}" FontWeight="Bold"
                               FontSize="30">
                </TextBlock>
                <TextBlock Text="(" Margin="5,0,0,0" Foreground="Gray"/>
                <TextBlock Text="{Binding BookCount}" Foreground="Gray"/>
                <TextBlock Text=")" Foreground="Gray"/>
            </StackPanel>
        </HierarchicalDataTemplate>

        <DataTemplate DataType="{x:Type local:Book}">
            <Border BorderBrush="LightBlue" BorderThickness="5" Margin="2,2,2,2"
                        Width="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth},
                    Converter={StaticResource LenConverter},ConverterParameter=100}"
                        Height="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight},
                    Converter={StaticResource LenConverter},ConverterParameter=2}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Grid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="FontSize" Value="30"/>
                            <Setter Property="Foreground" Value="Black"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="FontSize" Value="50"/>
                                    <Setter Property="Foreground" Value="Red"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Resources>
                    <TextBlock Text="Id:" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Id}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Name:" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Name}" Grid.Row="0" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="ISBN:" Grid.Row="0" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding ISBN}" Grid.Row="0" Grid.Column="5" HorizontalAlignment="Left"/>
                    <TextBlock Text="Author:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Author}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Comment:" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Comment}" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="Content:" Grid.Row="1" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Content}"  Grid.Row="1" Grid.Column="5" HorizontalAlignment="Left"/>
                    <TextBlock Text="Summary:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Summary}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"/>
                    <TextBlock Text="Title:" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Title}" Grid.Row="2" Grid.Column="3" HorizontalAlignment="Left"/>
                    <TextBlock Text="Title:" Grid.Row="2" Grid.Column="4" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding Topic}" Grid.Row="2" Grid.Column="5" HorizontalAlignment="Left"/>
                </Grid>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <TreeView ItemsSource="{Binding CategoryNodes}"
                  BorderThickness="1"
                  BorderBrush="LightGray"
                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                  ScrollViewer.VerticalScrollBarVisibility="Auto">
            <TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter Property="IsExpanded" Value="False"/>
                    <Setter Property="FontSize" Value="20"/>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    </Grid>
</Window>


//D:\C\WpfApp13\WpfApp13\MainWindow.xaml.cs
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Net.Http;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp13
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

    public partial class MainVM : ObservableObject
    {
        [ObservableProperty]
        private ObservableCollection<CategoryNode> categoryNodes;
        static HttpClient client;
        string originUrl = "http://localhost:51906/BookService.svc/getbookslist?cnt=";
        public MainVM()
        {
            client = new HttpClient();
            _ = InitDataAsync();
        }

        private async Task InitDataAsync(long cnt = 100)
        {
            string requestUrl = $"{originUrl}{cnt}";
            string jsonStr = await client.GetStringAsync(requestUrl);
            if (!string.IsNullOrWhiteSpace(jsonStr))
            {
                var bksList = JsonConvert.DeserializeObject<List<Book>>(jsonStr);
                if (bksList != null && bksList.Any())
                {
                    var groupedBooks = bksList.GroupBy(x => x.BookCategoryName)
                    .OrderBy(g => g.Key)
                    .Select(g => new CategoryNode
                    {
                        CategoryName = g.Key,
                        Books = new ObservableCollection<Book>(g.OrderBy(x => x.Id))
                    });
                    CategoryNodes = new ObservableCollection<CategoryNode>(groupedBooks);
                }
            }
        }
    }

    public class Book
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public string BookCategoryName { get; set; }
        public string ISBN { get; set; }
        public string Author { get; set; }
        public string Comment { get; set; }
        public string Content { get; set; }
        public string Summary { get; set; }
        public string Title { get; set; }
        public string Topic { get; set; }
    }


    public class CategoryNode
    {
        public string CategoryName { get; set; }
        public ObservableCollection<Book> Books { get; set; }
        public int BookCount => Books?.Count ?? 0;

        public CategoryNode()
        {
            Books = new ObservableCollection<Book>();
        }
    }

    public class LenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double dValue = 0;
            double dPara = 1;
            if (double.TryParse(value?.ToString(), out dValue) &&
                double.TryParse(parameter?.ToString(), out dPara))
            {
                if(dPara == 2.0)
                {
                    return dValue / dPara;
                }
                return dValue - dPara;
            }
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

image

image

image

image