RV
RV
CC#
Created by RV on 10/16/2024 in #help
WPF RichTextBox is very slow
I want to make a syntax highlighter with WPF. I chose to use RichTextBox but when trying to paste about 50,000 lines into WPF richtextbox, it takes about 10 minutes to complete as in this video. I compared with textbox on winform and wpf, and compared richtextbox on winform is faster. I also did syntax highlighter with update onscroll (not in rich text box) as at the end of the video and it can display faster. But when scrolling, over time the grid becomes have many objects (TextBlock) and becomes slow. How can I do syntax highlighter in WPF efficiently and quickly?
7 replies
CC#
Created by RV on 10/3/2024 in #help
✅ Callable Class
using System.Dynamic;

Run run = new Run();

run["Hello World"]();
Console.WriteLine(run[Run.Expression.SUM, 1, 2, 4, 2, 4]());

dynamic run2 = new Run();
run2();

class Run : DynamicObject
{
public enum Expression
{
SUM,
AVERAGE,
}
public override bool TryInvoke(InvokeBinder binder, object?[]? args, out object? result)
{
Console.WriteLine("Invoked");
result = null;
return true;
}

public Action this[string message] => () => Console.WriteLine(message);

public Func<double> this[Expression expression, params int[] _] => () =>
{
if (expression == Expression.SUM)
return _.Sum();
else
return _.Average();
};
}
using System.Dynamic;

Run run = new Run();

run["Hello World"]();
Console.WriteLine(run[Run.Expression.SUM, 1, 2, 4, 2, 4]());

dynamic run2 = new Run();
run2();

class Run : DynamicObject
{
public enum Expression
{
SUM,
AVERAGE,
}
public override bool TryInvoke(InvokeBinder binder, object?[]? args, out object? result)
{
Console.WriteLine("Invoked");
result = null;
return true;
}

public Action this[string message] => () => Console.WriteLine(message);

public Func<double> this[Expression expression, params int[] _] => () =>
{
if (expression == Expression.SUM)
return _.Sum();
else
return _.Average();
};
}
How to use Callable Class in C#? like
var d = Class1();
d();
var d = Class1();
d();
like in python __call__ or dart?
31 replies
CC#
Created by RV on 8/20/2024 in #help
EF Stupid, Why I get this error
No description
17 replies
CC#
Created by RV on 8/3/2024 in #help
Executing an App Without Admin Previleges
No description
4 replies
CC#
Created by RV on 7/27/2024 in #help
FindResource not work
I made a WPF Library (Net Framework 4.8) with Generix.xaml (in attach file) and CustomWindow.cs with DependencyProperty like this
public static readonly DependencyProperty TitleBarButtonStyleProperty =
DependencyProperty.Register(nameof(TitleBarButtonStyle), typeof(Style), typeof(CustomWindow),
new PropertyMetadata(Application.Current.FindResource("TitleBarButton")));

public Style TitleBarButtonStyle
{
get { return (Style)GetValue(TitleBarButtonStyleProperty); }
set { SetValue(TitleBarButtonStyleProperty, value); }
}


public static readonly DependencyProperty TitleBarExitButtonStyleProperty =
DependencyProperty.Register(nameof(TitleBarExitButtonStyle), typeof(Style), typeof(CustomWindow),
new PropertyMetadata(Application.Current.FindResource("TitleBarExitButton")));

public Style TitleBarExitButtonStyle
{
get { return (Style)GetValue(TitleBarExitButtonStyleProperty); }
set { SetValue(TitleBarExitButtonStyleProperty, value); }
}
public static readonly DependencyProperty TitleBarButtonStyleProperty =
DependencyProperty.Register(nameof(TitleBarButtonStyle), typeof(Style), typeof(CustomWindow),
new PropertyMetadata(Application.Current.FindResource("TitleBarButton")));

public Style TitleBarButtonStyle
{
get { return (Style)GetValue(TitleBarButtonStyleProperty); }
set { SetValue(TitleBarButtonStyleProperty, value); }
}


public static readonly DependencyProperty TitleBarExitButtonStyleProperty =
DependencyProperty.Register(nameof(TitleBarExitButtonStyle), typeof(Style), typeof(CustomWindow),
new PropertyMetadata(Application.Current.FindResource("TitleBarExitButton")));

public Style TitleBarExitButtonStyle
{
get { return (Style)GetValue(TitleBarExitButtonStyleProperty); }
set { SetValue(TitleBarExitButtonStyleProperty, value); }
}
But thrown an error ResourceReferenceKeyNotFoundException: 'TitleBarButton' resource not found. Help plis
1 replies
CC#
Created by RV on 7/3/2024 in #help
How to link C++ library to C#, and make C++ library cannot to decompile?
No description
2 replies
CC#
Created by RV on 4/20/2024 in #help
Inheritance Cast
No description
5 replies
CC#
Created by RV on 11/4/2023 in #help
❔ How to check Validation Error programically C# in MVVM?
No description
11 replies
CC#
Created by RV on 11/3/2023 in #help
❔ Validation Error auto resize parent
No description
4 replies
CC#
Created by RV on 10/25/2023 in #help
❔ PopupModal dialog not fadeout or fadein
Popup Modal not fadeout when click close button, or when open from menu PopupModal.cs
using Kasir.Commons.Commands;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Kasir.Utils.Controls
{
internal class PopupModal : ContentControl
{

event EventHandler PopupClosed;
public ICommand DismissCommand { get; }

static PopupModal()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PopupModal), new FrameworkPropertyMetadata(typeof(PopupModal)));
}

public PopupModal()
{
DismissCommand = new RelayCommand(Dismiss);
}

private void Dismiss(object view) => IsOpen = false;

public bool IsOpen
{
get { return (bool)GetValue(IsOpenProperty); }
set {
SetValue(IsOpenProperty, value);
if (!value) PopupClosed?.Invoke(this, EventArgs.Empty);
}
}

public static readonly DependencyProperty IsOpenProperty =
DependencyProperty.Register("IsOpen", typeof(bool), typeof(PopupModal), new PropertyMetadata(false));

public string Header
{
get { return (string)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(string), typeof(PopupModal), new PropertyMetadata("Message Popup"));
}
}
using Kasir.Commons.Commands;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Kasir.Utils.Controls
{
internal class PopupModal : ContentControl
{

event EventHandler PopupClosed;
public ICommand DismissCommand { get; }

static PopupModal()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PopupModal), new FrameworkPropertyMetadata(typeof(PopupModal)));
}

public PopupModal()
{
DismissCommand = new RelayCommand(Dismiss);
}

private void Dismiss(object view) => IsOpen = false;

public bool IsOpen
{
get { return (bool)GetValue(IsOpenProperty); }
set {
SetValue(IsOpenProperty, value);
if (!value) PopupClosed?.Invoke(this, EventArgs.Empty);
}
}

public static readonly DependencyProperty IsOpenProperty =
DependencyProperty.Register("IsOpen", typeof(bool), typeof(PopupModal), new PropertyMetadata(false));

public string Header
{
get { return (string)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(string), typeof(PopupModal), new PropertyMetadata("Message Popup"));
}
}
4 replies