Skip to content

Instantly share code, notes, and snippets.

<Style x:Key="MaterialDesignAccentButtonStyle" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="{StaticResource Accent}"/>
<Setter Property="BorderBrush" Value="{StaticResource AccentDark}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="16,3,16,3"/>
<Setter Property="FontSize" Value="16"/>
@LoriBru
LoriBru / MainView.xaml
Created January 14, 2019 11:26
This snippet sets the input binding on a window.
<Window.InputBindings>
<KeyBinding Command="{Binding Command}" Key="F10"></KeyBinding>
</Window.InputBindings>
@LoriBru
LoriBru / MainView.xaml
Created January 14, 2019 11:25
This property sets the high quality option for bitmap scaling.
<Window.Resources>
<Style TargetType="Image">
<Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality" />
</Style>
<Style TargetType="ContentControl">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</Window.Resources>
@LoriBru
LoriBru / MainView.cs
Last active January 23, 2019 15:36
This method how to load a new page as UserControl into the main ContentControl.
MainWindow mainWindowInstance;
public SearchDeviceView(MainWindow mainWindow)
{
InitializeComponent();
mainWindowInstance = mainWindow;
var viewModel = (Presenter)mainWindow.DataContext;
viewModel.ViewEvent += ViewModel_ViewEvent;
SearchDeviceViewShowing = true;
}
@LoriBru
LoriBru / MainVM.cs
Created January 14, 2019 11:20
Force the application to shut down.
Application.Current.Dispatcher.Invoke(Application.Current.Shutdown);
@LoriBru
LoriBru / RelayCommand.cs
Created January 14, 2019 11:19
Assign a RelayCommand to a method.
OneCommand = new RelayCommand(o => OneMethod(), o => true);
@LoriBru
LoriBru / MainVM.cs
Created January 14, 2019 11:18
Setting shutdown mode to OnMainWindowClose so that all pending tasks will terminate when closing the main window.
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
@LoriBru
LoriBru / RelayCommand.cs
Created January 14, 2019 11:18
RelayCommand class
/// <summary>
/// Interface for commands to use in MVVM Pattern. It implements ICommand interface.
/// </summary>
public class RelayCommand : ICommand
{
readonly Action<object> execute;
readonly Func<object, bool> canExecute;
/// <summary>
/// CanExecuteChanged event handler.
@LoriBru
LoriBru / MainVM.cs
Created January 14, 2019 11:16
Full property with OnpropertyChanged
string name;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged(nameof(Name));
}
@LoriBru
LoriBru / MainVM.cs
Last active January 14, 2019 10:49
This method converts a hex string to a byte array.
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}