Honza K.
Honza K.
CC#
Created by Honza K. on 3/29/2024 in #help
Avalonia UI - binding in markup extension?
public class StringLocalizationExtension : MarkupExtension
{
#pragma warning disable IDE0290 // Use primary constructor
public StringLocalizationExtension(string key)
{
Key = key;
}
#pragma warning restore IDE0290 // Use primary constructor
public string? Key { get; set; }

public override object ProvideValue(IServiceProvider serviceProvider)
{
var binding = new ReflectionBindingExtension($"[{Key}]")
{
Mode = BindingMode.OneWay,
Source = Internal.StringLocalizationResolver.Instance,
};

return binding.ProvideValue(serviceProvider);
}
}

public class StringLocalizationResolver(ICAFluentUINet.Abstractions.Localization.IStringLocalizer stringLocalizer) : INotifyPropertyChanged
{
private readonly IStringLocalizer _stringLocalizer = stringLocalizer;
private const string IndexerName = "Item";
private const string IndexerArrayName = "Item[]";

#pragma warning disable CS8612 // Nullability of reference types in type doesn't match implicitly implemented member.
public event PropertyChangedEventHandler PropertyChanged;
#pragma warning restore CS8612 // Nullability of reference types in type doesn't match implicitly implemented member.
public static StringLocalizationResolver? Instance { get; set; }

public string this[string key] => _stringLocalizer.Get(key);

public void Invalidate()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(IndexerName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(IndexerArrayName));
}
}
public class StringLocalizationExtension : MarkupExtension
{
#pragma warning disable IDE0290 // Use primary constructor
public StringLocalizationExtension(string key)
{
Key = key;
}
#pragma warning restore IDE0290 // Use primary constructor
public string? Key { get; set; }

public override object ProvideValue(IServiceProvider serviceProvider)
{
var binding = new ReflectionBindingExtension($"[{Key}]")
{
Mode = BindingMode.OneWay,
Source = Internal.StringLocalizationResolver.Instance,
};

return binding.ProvideValue(serviceProvider);
}
}

public class StringLocalizationResolver(ICAFluentUINet.Abstractions.Localization.IStringLocalizer stringLocalizer) : INotifyPropertyChanged
{
private readonly IStringLocalizer _stringLocalizer = stringLocalizer;
private const string IndexerName = "Item";
private const string IndexerArrayName = "Item[]";

#pragma warning disable CS8612 // Nullability of reference types in type doesn't match implicitly implemented member.
public event PropertyChangedEventHandler PropertyChanged;
#pragma warning restore CS8612 // Nullability of reference types in type doesn't match implicitly implemented member.
public static StringLocalizationResolver? Instance { get; set; }

public string this[string key] => _stringLocalizer.Get(key);

public void Invalidate()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(IndexerName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(IndexerArrayName));
}
}
2 replies
CC#
Created by Kagano on 2/26/2024 in #help
✅ Avalonia UI button doesn't color by hover!
you must change it in the template itself...
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource Button.MouseOver.Background}"/>
<Setter Property="TextBlock.Foreground" Value="{DynamicResource Button.Foreground}"/>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource Button.MouseOver.Background}"/>
<Setter Property="TextBlock.Foreground" Value="{DynamicResource Button.Foreground}"/>
</Style>
4 replies
CC#
Created by 𝕭𝖔𝖙𝖙𝖑𝖊_𝕭𝖆𝖗𝖔𝖓 on 2/23/2024 in #help
Trying to scaffold a controller for ASP .NET api using MongoDB but get this message
This shit gets broken quite often actually... I never managed to fix it, I always created a new empty project and did the scaffold action there and just copied the stuff out to my actual project 😄
5 replies
CC#
Created by Shiv on 2/19/2024 in #help
Scheduling task in c# with failproof mechanism
thanks for the info, my answer is based purely on the Nick's video and I didn't look at the library myself... It's good to know it is a paid library and the free version kinda sucks
14 replies
CC#
Created by Shiv on 2/19/2024 in #help
Scheduling task in c# with failproof mechanism
14 replies
CC#
Created by stuw on 1/8/2024 in #help
Parallel.For but that doesn't allocate.
what are you comparing it against? if you want to benchmark something, try using this https://github.com/dotnet/BenchmarkDotNet
4 replies
CC#
Created by Mayka on 1/8/2024 in #help
WPF Data Binding Shows Blank
Also you might want to consider creating a viewmodel instead of setting datacontext to the view itself
9 replies
CC#
Created by Mayka on 1/8/2024 in #help
WPF Data Binding Shows Blank
All properties that are used for binding must be public
9 replies
CC#
Created by Justdie on 1/5/2024 in #help
import every function from a C module
No, it's still one to one relationship... One DllImport per function, is it annoying? If you have many functions, yes 😄
6 replies
CC#
Created by Asurblått on 1/3/2024 in #help
Null Reference error but it's not null?
can you send the call stack from the exception?
49 replies
CC#
Created by Asurblått on 1/3/2024 in #help
Null Reference error but it's not null?
show us the call stack pls
49 replies
CC#
Created by mauriziopatino on 1/2/2024 in #help
WPF Visibility binding seems that is not setting style
oh, my bad for not reading your question/problem properly 😄 sry
11 replies
CC#
Created by mauriziopatino on 1/2/2024 in #help
WPF Visibility binding seems that is not setting style
or you can use binding converter
11 replies
CC#
Created by mauriziopatino on 1/2/2024 in #help
WPF Visibility binding seems that is not setting style
I dont think the property can be of type string, it should be of a correct type, which is Visibility in this case
11 replies
CC#
Created by UltraWelfare on 12/26/2023 in #help
Organizing and naming different closely related Dtos
what I want to say is, consider building the API for the needs of the UI, it can save you a lot of work and it could actually also save you some troubleshooting
47 replies
CC#
Created by UltraWelfare on 12/26/2023 in #help
Organizing and naming different closely related Dtos
at work we have an API for a service, the service is public but we're the only one using the API and we're distributing the client apps... and let me tell you, the API is done exactly as REST API should be... but oh boy, it has so many endpoints and it's so fucking complex to do the simplest things... I wish the API was tailored to the applications... To get an account that owns a device, I have to get account id from the device detail, to get the device detail i have to fetch it via device id and then fetch the owning account... Why? because that's how the rest api should be... We have 3 applications, no client ever can call the API itself (we won'T give them the crypto protocol documentation so they couldn't authorize :D) but no, there cannot be an endpoint that would give the app exactly what the app needs, that would go against the api design
47 replies
CC#
Created by UltraWelfare on 12/26/2023 in #help
Organizing and naming different closely related Dtos
maybe you could build the API exactly for the needs of your UI?
47 replies
CC#
Created by UltraWelfare on 12/26/2023 in #help
Organizing and naming different closely related Dtos
i see
47 replies