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

推荐订阅源

D
Docker
S
SegmentFault 最新的问题
博客园 - 司徒正美
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
B
Blog RSS Feed
Jina AI
Jina AI
NISL@THU
NISL@THU
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
T
Threatpost
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
I
Intezer
Vercel News
Vercel News
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
MyScale Blog
MyScale Blog
I
InfoQ
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
博客园 - 叶小钗
The Hacker News
The Hacker News
U
Unit 42
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
Engineering at Meta
Engineering at Meta
小众软件
小众软件
F
Full Disclosure
G
Google Developers Blog
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Securelist
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
Security Latest
Security Latest
V
V2EX
Recent Announcements
Recent Announcements
S
Schneier on Security
量子位
L
Lohrmann on Cybersecurity
H
Help Net Security
博客园 - Franky
博客园_首页

博客园 - FredGrit

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<datagrid> 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 - FredGrit WPF DataGrid behavior customize command and command parameter then invoke and implemented in MVVM - FredGrit 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("o") 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("{cnt}"] pass argument WPF implement ICommand with async execute WPF ListBox control virtualization in mvvm WPF Data Source invoke from web api C# WebAPI
WPF ContextMenu does not rely on host visual tree, the Freezable can exist independently, convey dependency property in usercontrol to caller
FredGrit · 2026-06-14 · via 博客园 - FredGrit
public class ProxyBinding : Freezable
{
    protected override Freezable CreateInstanceCore()
    {
        return new ProxyBinding();
    }

    public object SourceObject
    {
        get { return (object)GetValue(SourceObjectProperty); }
        set { SetValue(SourceObjectProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SourceObject.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SourceObjectProperty =
        DependencyProperty.Register(
            nameof(SourceObject), 
            typeof(object), 
            typeof(ProxyBinding), 
            new PropertyMetadata(null));
}


<UserControl.Resources>
    <local:ProxyBinding x:Key="ProxyBinding"
                        SourceObject="{Binding RelativeSource={RelativeSource 
        AncestorType=UserControl}}"/>
</UserControl.Resources>

 <ContextMenu>
     <MenuItem Header="{Binding SourceObject.UCFirstMIHeader,
         Source={StaticResource ProxyBinding}}"
               Command="{Binding SourceObject.UCFirstMICmd,
         Source={StaticResource ProxyBinding}}"/>
 </ContextMenu>
<MenuItem Header="{Binding SourceObject.UCFirstMIHeader,
    Source={StaticResource ProxyBinding}}"
          Command="{Binding SourceObject.UCFirstMICmd,
    Source={StaticResource ProxyBinding}}"/>
<UserControl x:Class="WpfApp6.UCDG"
             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:WpfApp6"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <local:ProxyBinding x:Key="ProxyBinding"
                            SourceObject="{Binding RelativeSource={RelativeSource 
            AncestorType=UserControl}}"/>
    </UserControl.Resources>
    <Grid>
        <DataGrid ItemsSource="{Binding UCDGCollection,
                  RelativeSource={RelativeSource AncestorType=UserControl}}"
                  AutoGenerateColumns="True"
                  VirtualizingPanel.IsVirtualizing="True"
                  VirtualizingPanel.VirtualizationMode="Recycling"
                  VirtualizingPanel.CacheLength="5,5"
                  VirtualizingPanel.CacheLengthUnit="Item"
                  ScrollViewer.IsDeferredScrollingEnabled="True"
                  ScrollViewer.CanContentScroll="True"
                  EnableRowVirtualization="True"
                  EnableColumnVirtualization="True"
                  UseLayoutRounding="True"
                  SnapsToDevicePixels="True" 
                  IsReadOnly="True">
            <DataGrid.Resources>
                <Style TargetType="DataGridRow">
                    <Setter Property="FontSize" Value="30"/>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="FontSize" Value="50"/>
                            <Setter Property="Foreground" Value="Red"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{Binding SourceObject.UCFirstMIHeader,
                        Source={StaticResource ProxyBinding}}"
                              Command="{Binding SourceObject.UCFirstMICmd,
                        Source={StaticResource ProxyBinding}}"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>
    </Grid>
</UserControl>


using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection.Metadata;
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 WpfApp6
{
    /// <summary>
    /// Interaction logic for UCLbx.xaml
    /// </summary>
    public partial class UCDG : UserControl
    {
        public UCDG()
        {
            InitializeComponent();
        }


        public IList UCDGCollection
        {
            get { return (IList)GetValue(UCDGCollectionProperty); }
            set { SetValue(UCDGCollectionProperty, value); }
        }

        // Using a DependencyProperty as the backing store for UCDGCollection.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UCDGCollectionProperty =
            DependencyProperty.Register(
                nameof(UCDGCollection), 
                typeof(IList), 
                typeof(UCDG), 
                new PropertyMetadata(null));

        public string UCFirstMIHeader
        {
            get { return (string)GetValue(UCFirstMIHeaderProperty); }
            set { SetValue(UCFirstMIHeaderProperty, value); }
        }

        // Using a DependencyProperty as the backing store for UCFirstMIHeader.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UCFirstMIHeaderProperty =
            DependencyProperty.Register(
                nameof(UCFirstMIHeader), 
                typeof(string), 
                typeof(UCDG), 
                new PropertyMetadata(null));






        public DelCmd UCFirstMICmd
        {
            get { return (DelCmd)GetValue(UCFirstMICmdProperty); }
            set { SetValue(UCFirstMICmdProperty, value); }
        }

        // Using a DependencyProperty as the backing store for UCFirstMICmd.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UCFirstMICmdProperty =
            DependencyProperty.Register(
                nameof(UCFirstMICmd),
                typeof(DelCmd),
                typeof(UCDG),
                new PropertyMetadata(null));


    }

    

    public class ProxyBinding : Freezable
    {
        protected override Freezable CreateInstanceCore()
        {
            return new ProxyBinding();
        }

        public object SourceObject
        {
            get { return (object)GetValue(SourceObjectProperty); }
            set { SetValue(SourceObjectProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SourceObject.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SourceObjectProperty =
            DependencyProperty.Register(
                nameof(SourceObject), 
                typeof(object), 
                typeof(ProxyBinding), 
                new PropertyMetadata(null));
    }

    public class DelCmd : ICommand
    {
        private Action<object?> execute;
        private Func<object?, bool>? canExecute;
        public DelCmd(Action<object?> executeValue, Func<object?, bool>? canExecuteValue=null)
        {
            execute = executeValue ?? throw new ArgumentNullException(nameof(executeValue));
            canExecute= canExecuteValue;
        }

        public event EventHandler? CanExecuteChanged;

        public bool CanExecute(object? parameter)
        {
            return canExecute == null ? true : canExecute(parameter);
        }

        public void Execute(object? parameter)
        {
            if(!CanExecute(parameter))
            {
                return;
            }
            execute?.Invoke(parameter);            
        }

        public void RaiseCanExecuteChanged()
        {
            var handler = Volatile.Read(ref CanExecuteChanged);
            if (handler == null)
            {
                return;
            }

            if (Application.Current?.Dispatcher?.CheckAccess() == true)
            {
                handler?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                Application.Current?.Dispatcher?.Invoke(() =>
                {
                    handler?.Invoke(this, EventArgs.Empty);
                });
            }
        }
    }
}


<Window x:Class="WpfApp6.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:WpfApp6"
        mc:Ignorable="d"
        Title="{Binding MainTitle}"
        WindowState="Maximized">
    <Window.DataContext>
        <local:MainVM/>
    </Window.DataContext>
    <Grid>
        <local:UCDG UCDGCollection="{Binding BooksCollection}"
                    UCFirstMIHeader="{Binding FirstHeader}"
                    UCFirstMICmd="{Binding FirstMICmd}"
                    />
    </Grid>
</Window>


using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net.Http;
using System.Runtime.CompilerServices;
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;
using Newtonsoft.Json;

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

    public class MainVM : INotifyPropertyChanged
    {
        string originalUrl = "http://localhost:8080/getbookslist?count=";
        HttpClient client;
        private bool isLoadind = false;
        private object loadingObj = new object();

        public MainVM()
        {
            if(!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                client = new HttpClient();
                Task.Run(async () =>
                {
                    await LoadDataFromServerRelentless();
                });
            }
        }

        private async Task LoadDataFromServerRelentless()
        {
            while (true)
            {
                await InitBooksCollectionAsync();
                await Task.Delay(20000);
            }
        }

        private async Task InitBooksCollectionAsync(int cnt=1000000)
        {
            lock(loadingObj)
            {
                if(isLoadind)
                {
                    return;
                }
                isLoadind = true;
            }

            try
            {
                await Application.Current?.Dispatcher?.InvokeAsync(() =>
                {
                    MainTitle = $"{DateTime.Now.ToString("yyyyMMddHHmmssffff")},loading...";
                    BooksCollection?.Clear();
                });

                string requestUrl = $"{originalUrl}{cnt}";
                string jsonStr = await client.GetStringAsync(requestUrl).ConfigureAwait(false);
                if (!string.IsNullOrWhiteSpace(jsonStr))
                {
                    List<Book>? bksList = Newtonsoft.Json.JsonConvert.
                        DeserializeObject<List<Book>>(jsonStr);

                    if (bksList != null && bksList.Any())
                    {
                        await Application.Current?.Dispatcher?.InvokeAsync(() =>
                        {
                            BooksCollection = new ObservableCollection<Book>(bksList);
                            MainTitle = $"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}," +
                            $"loaded {BooksCollection?.Count} items," +
                            $"first Id:{BooksCollection[0]?.Id}," +
                            $"Last Id:{BooksCollection[^1]?.Id}";
                        }, System.Windows.Threading.DispatcherPriority.Background);
                    }
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine($"{DateTime.Now},{ex?.Message}");
#else
                System.Diagnostics.Trace.WriteLine($"{DateTime.Now},{ex?.Message}");
#endif
            }
            finally
            {
                isLoadind = false;
            }           
        }

        private ICommand firstMICmd;
        public ICommand FirstMICmd
        {
            get
            {
                if(firstMICmd==null)
                {
                    firstMICmd = new DelCmd(FirstMICmdExecuted);
                }
                return firstMICmd;
            }
        }

        private void FirstMICmdExecuted(object? obj)
        {
             
        }

        private string firstHeader="First Header";
        public string FirstHeader
        {
            get
            {
                return firstHeader;
            }
            set
            {
                if(value!=firstHeader)
                {
                    firstHeader = value;
                    OnPropertyChanged();
                }
            }
        }

        private string mainTitle = $"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}";
        public string MainTitle
        {
            get
            {
                return mainTitle;
            }
            set
            {
                if(value!=mainTitle)
                {
                    mainTitle = value;
                    OnPropertyChanged();
                }
            }
        }

        private ObservableCollection<Book> booksCollection;
        public ObservableCollection<Book> BooksCollection
        {
            get
            {
                return booksCollection;
            }
            set
            {
                if(value!=booksCollection)
                {
                    booksCollection = value;
                    OnPropertyChanged();
                }
            }
        }

        public event PropertyChangedEventHandler? PropertyChanged;
        private void OnPropertyChanged([CallerMemberName] string propName="")
        {
            var handler = Volatile.Read(ref PropertyChanged);
            if (handler == null)
            {
                return;
            }
            handler?.Invoke(this, new PropertyChangedEventArgs(propName));
        }
    }

    public class Book
    {
        public int Id { get; set; }
        public string Name { 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; }
    }
}

image

image

image

image

image

image