1、细说wpf控件
https://www.cnblogs.com/huangxincheng/archive/2012/07/09/2582062.html
2、用户控件
(1)创建xaml(选择用户控件WPF)
1 <UserControl x:Class="WpfApplication8.AddProduct" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 6 mc:Ignorable="d" 7 d:DesignHeight="200" d:DesignWidth="300"> 8 <Grid Height="171" Width="262"> 9 <TextBlock Height="20" HorizontalAlignment="Left" Margin="28,57,0,0" Name="textBlock1" Text="名称:" VerticalAlignment="Top" Width="42" /> 10 <TextBlock Height="20" HorizontalAlignment="Left" Margin="28,92,0,0" Name="textBlock2" Text="价格:" VerticalAlignment="Top" Width="42" /> 11 <TextBox Height="23" HorizontalAlignment="Left" Margin="76,54,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" /> 12 <TextBox Height="23" HorizontalAlignment="Left" Margin="76,92,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" /> 13 </Grid> 14 </UserControl>
(2)在MainWindow中引用
1 <Window x:Class="WpfApplication8.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:local="clr-namespace:WpfApplication8" 5 Title="MainWindow" Height="350" Width="525"> 6 <Grid> 7 <local:AddProduct x:Name="test"/> 8 </Grid> 9 </Window>