728x90
반응형
[이미지 출력 방법1]
[xaml]
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="486.8" >
<Grid x:Name="aaa">
<Image Width="400" Source="aaa.png"/>
</Grid>
</Window>
[이미지 출력 방법1]
[xaml.cs]
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;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Reflection;
using System.IO;
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Image img = new Image();
img.Source = new BitmapImage(
new Uri(@"aaa.png", UriKind.Relative));
img.Width = 400;
img.Height = 200;
this.aaa.Children.Add(img);
}
}
}
[이미지 출력 방법2]
[xaml]
Canvas
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="486.8" >
<Canvas>
<Rectangle Name="manRect" Width="400" Height="300">
<Rectangle.Fill>
<ImageBrush ImageSource="aaa.png"/>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Window>
[xaml]
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="486.8" ButtonBase.Click = "Window_Click">
<Grid>
<StackPanel Margin="20" ButtonBase.Click="StackPanel_Click">
<StackPanel Margin="10">
<TextBlock Name="txt1" FontSize="18" Margin="5"
Text="This is a Text Block 1"/>
<TextBlock Name="txt2" FontSize="18" Margin="5"
Text="This is a Text Block 2"/>
<TextBlock Name="txt3" FontSize="18" Margin="5"
Text="This is a Text Block 3"/>
</StackPanel>
<Button Margin="10" Content="Click_Me" Click="Button_Click" Width="80"/>
</StackPanel>
</Grid>
</Window>
[xaml.cs]
e.Handled = true; // 키가 눌린 이벤트가 다 처리되었으니 신경쓰지않아도 된다는 뜻
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("1");
txt1.Text = "1";
e.Handled = true;
}
private void StackPanel_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("2");
txt1.Text = "2";
}
private void Window_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("3");
txt1.Text = "3";
}
}
}
728x90
반응형
'Education > Edu | .net' 카테고리의 다른 글
# 39) [OPENCV] 2.기본다지기 (0) | 2021.03.12 |
---|---|
# 38) [OPENCV] 1.기본다지기 (0) | 2021.03.11 |
# 36.3) [C#] [Design Pattern] Command Pattern (0) | 2021.03.08 |
# 36.2) [WPF] 기본다지기4 (binding) (0) | 2021.03.08 |
# 36.1) [WPF] 기본다지기3 (binding) (0) | 2021.03.08 |