Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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.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>
<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"/>
<Style x:Key="TransparentButtonStyle" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="{x:Null}"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{StaticResource PrimaryDark}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="Template">
<TargetType="{x:Type ProgressBar}">
<Setter Property="Foreground" Value="{StaticResource Primary}"/>
<Setter Property="Background" Value="#EEEEEE"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid Name="TemplateRoot" SnapsToDevicePixels="true">
<Rectangle Fill="{TemplateBinding Background}"/>
<Rectangle Name="PART_Track" Margin="0"/>
@LoriBru
LoriBru / MainVM.cs
Created January 14, 2019 11:32
This method check the presence of internet connection.
public static bool CheckConnection()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.microsoft.com");
request.Timeout = 5000;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
@LoriBru
LoriBru / MainActivity.cs
Created January 14, 2019 11:45
Changing status bar color if version is Lollipop or newer.
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
var color = Color.Argb(210, 57, 169, 220);
Window.SetStatusBarColor(color);
}
@LoriBru
LoriBru / MainActivity.cs
Created January 14, 2019 11:46
Set our view from the "main" layout resource which contains a FrameLayout.
SetContentView(Resource.Layout.FrameContainer);