Skip to content

Instantly share code, notes, and snippets.

View somapatrik's full-sized avatar

Patrik Šoma somapatrik

View GitHub Profile
@somapatrik
somapatrik / cmdhnd.snippet
Last active January 3, 2024 07:11
Command + Handler snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Command with handler</Title>
<Author>Patrik Šoma</Author>
<Description>SLM Only!</Description>
<Shortcut>cmdhnd</Shortcut>
</Header>
<Snippet>
@somapatrik
somapatrik / qryhnd.snippet
Last active January 3, 2024 07:11
Query + Handler
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Query with handler</Title>
<Author>Patrik Šoma</Author>
<Description>SLM only!</Description>
<Shortcut>qryhnd</Shortcut>
</Header>
<Snippet>
@somapatrik
somapatrik / RelayCommand.cs
Created November 20, 2023 10:20
WPF Relay Command
public class RelayCommand : ICommand
{
private Action<object> _execute;
private Func<object, bool> _canExecute;
public RelayCommand(Action<object> execute)
{
_execute = execute;
_canExecute = null;
@somapatrik
somapatrik / PrimeViewModel.cs
Created November 20, 2023 10:15
ViewModel parent class
public class PrimeViewModel : INotifyPropertyChanged
{
protected bool SetProperty<T>(ref T backingStore, T value,
[CallerMemberName] string propertyName = "",
Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
backingStore = value;
@somapatrik
somapatrik / test.cs
Created September 26, 2023 07:06
Run WPF inside Forms
MyWpfProject.MainWindow mw = new MyWpfProject.MainWindow();
ElementHost.EnableModelessKeyboardInterop(mw);
mw.Show();
<Color x:Key="Primary">#0b5ed7</Color>
<Color x:Key="GridBackground">#4F000000</Color>
<Color x:Key="NexenColor">#9d1c9d</Color>
<Color x:Key="SomaDarkDark">#22272e</Color>
<Color x:Key="SomaDarkLight">#434c57</Color>
<Color x:Key="GithubDark">#24292f</Color>
<Color x:Key="GithubLight">#f6f8fa</Color>
<Color x:Key="GithubRed">#cf222e</Color>
<Color x:Key="GithubGreen">#2da44e</Color>
<!-- Example of conditional styling -->
<Label Grid.Row="2" Grid.Column="1" Text="{Binding Material.ITEM_STATE_FORMAT}" HorizontalOptions="Center" Style="{StaticResource detailText}">
<Label.Triggers>
<DataTrigger Binding="{Binding Material.State}" TargetType="Label" Value="B">
<Setter Property="Style" Value="{StaticResource detailText}" />
</DataTrigger>
<DataTrigger Binding="{Binding Material.State}" TargetType="Label" Value="N">
<Setter Property="Style" Value="{StaticResource detailTextError}" />
</DataTrigger>
</Label.Triggers>
@somapatrik
somapatrik / MultipleTasks.cs
Last active November 11, 2021 10:33
Parallel execution of several tasks
// Create tasks, must use Task.Run() not new Task()
Task expireTask = Task.Run(()=> { ExpireCheck(); });
Task agingTask = Task.Run(() => { AgingCheck(); });
Task fifoTask = Task.Run(() => { FIFOCheck(); });
Task novalidTask = Task.Run(() => { NoValidCheck(); });
Task nolifeTask = Task.Run(() => { NoLifeCheck(); });
// Add them to list
List<Task> tasks = new List<Task>();
tasks.Add(expireTask);
@somapatrik
somapatrik / snmplistener.cs
Created April 29, 2021 13:42
SNMP listener
// Prototype server for SNMP
Socket socket;
EndPoint ep;
byte[] buffer;
ManualResetEvent manualevent = new ManualResetEvent(false);
private void btnListener_Click(object sender, RoutedEventArgs e)
{
// Construct a socket and bind it to the trap manager port 162
@somapatrik
somapatrik / gist:3bae93abf0ece3faf0b10fe29578dc74
Created January 17, 2021 08:46 — forked from hansmaad/gist:9187633
WPF Flat Combo Box Style
<!-- Flat ComboBox -->
<SolidColorBrush x:Key="ComboBoxNormalBorderBrush" Color="#e3e9ef" />
<SolidColorBrush x:Key="ComboBoxNormalBackgroundBrush" Color="#fff" />
<SolidColorBrush x:Key="ComboBoxDisabledForegroundBrush" Color="#888" />
<SolidColorBrush x:Key="ComboBoxDisabledBackgroundBrush" Color="#eee" />
<SolidColorBrush x:Key="ComboBoxDisabledBorderBrush" Color="#888" />
<ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate">
<Grid>
<Grid.ColumnDefinitions>