Skip to content

Instantly share code, notes, and snippets.

@rmcdongit
Last active December 4, 2020 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcdongit/64273465ff88aa20ce2e8490e18aa03d to your computer and use it in GitHub Desktop.
Save rmcdongit/64273465ff88aa20ce2e8490e18aa03d to your computer and use it in GitHub Desktop.
SampleWPF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Demo
{
/// <summary>
/// Interaction logic for Construct.xaml
/// </summary>
public partial class Construct : Page
{
public string[] Characters = new string[3] { "aang.jpg", "katara.jpg", "toph.jpg" };
public Random R = new Random();
public int c = 0;
public Construct()
{
InitializeComponent();
}
private void Character_Checked(object sender, RoutedEventArgs e)
{
// which button was clicked?
var button = sender as RadioButton;
//what to do with selection?
switch (button.Content.ToString())
{
case "Aang":
c = 0;
break;
case "Katara":
c = 1;
break;
case "Toph":
c = 2;
break;
}
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
recChar.Fill = new ImageBrush
{
ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/Demo;component/img/" + Characters[c], UriKind.Absolute))
};
}
private void btnRand_Click(object sender, RoutedEventArgs e)
{
c = R.Next(0, Characters.Length);
recChar.Fill = new ImageBrush
{
ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/Demo;component/img/" + Characters[c], UriKind.Absolute))
};
}
}
}
<Window x:Class="Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Demo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid Background="DarkSeaGreen">
<Frame x:Name="Navigation" NavigationUIVisibility="Hidden" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Demo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Navigation.Navigate(new Welcome());
}
}
}
<Page x:Class="Demo.Welcome"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Demo"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Welcome">
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="85,128,0,0" TextWrapping="Wrap" Text="Character Chooser" VerticalAlignment="Top" Height="118" Width="610" FontSize="72" Foreground="White"/>
<Button x:Name="btnStart" Content="Start" HorizontalAlignment="Left" Margin="333,272,0,0" VerticalAlignment="Top" Width="99" Background="{x:Null}" Foreground="White" FontSize="22" Height="37" Click="btnStart_Click" BorderBrush="{x:Null}"/>
<Button x:Name="btnQuit" Content="Quit" HorizontalAlignment="Left" Margin="333,325,0,0" VerticalAlignment="Top" Width="99" BorderBrush="{x:Null}" Foreground="White" Background="{x:Null}" FontSize="22" Click="btnQuit_Click"/>
</Grid>
</Page>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Demo
{
/// <summary>
/// Interaction logic for Welcome.xaml
/// </summary>
public partial class Welcome : Page
{
public Welcome()
{
InitializeComponent();
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("Construct.xaml", UriKind.Relative));
}
private void btnQuit_Click(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment