[WPFピクチャ ビューアーの作成]をダウンロードする。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:self="clr-namespace:WpfAPictureViewer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<WindowsFormsHost x:Name="wfHost" Grid.Row="0">
<self:UserControl1 x:Name="myControl" />
</WindowsFormsHost>
<StackPanel Grid.Row="1" Name="StackPanel1" Orientation="Horizontal">
<CheckBox Content="Stretch" Height="16" Width="100" Name="CheckBox1" IsChecked="True" />
<Button Content="Show a picture" Height="23" Name="Button1" />
<Button Content="Clear the picture" Height="23" Name="Button2" />
<Button Content="Set the background color" Height="23" Name="Button3" />
<Button Content="Close" Height="23" Name="Button4" />
</StackPanel>
</Grid>
</Window>
using System.Windows;
namespace WpfAPictureViewer
{
public partial class MainWindow : Window
{
public MainWindow()
{InitializeComponent(); }
private void Button1_Click(object sender, RoutedEventArgs e)
{
if (myControl.OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{myControl.PictureBox1.Load(myControl.OpenFileDialog1.FileName);}
}
private void Button2_Click(object sender, RoutedEventArgs e)
{myControl.PictureBox1.Image = null;}
private void Button3_Click(object sender, RoutedEventArgs e)
{
if (myControl.ColorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ myControl.PictureBox1.BackColor = myControl.ColorDialog1.Color;}
}
private void Button4_Click(object sender, RoutedEventArgs e)
{ Close();}
private void CheckBox1_Checked(object sender, RoutedEventArgs e)
{ myControl.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;}
private void CheckBox1_Unchecked(object sender, RoutedEventArgs e)
{ myControl.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;}
}
}