wpf 中如何引用自定义控件
程序员文章站
2022-03-04 11:13:02
...
Ellis.yaml
<UserControl x:Class="WpfApplication.UserControlItems.Ellis"
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:WpfApplication.UserControlItems"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
<TextBlock Text="123"/>
<TextBox />
</StackPanel>
</UserControl>
main.yaml
<Window x:Class="WpfApplication.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:WpfApplication"
mc:Ignorable="d"
xmlns:ellis="clr-namespace:WpfApplication.UserControlItems"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ellis:Ellis x:Name="test"/>
</Grid>
</Window>
首先需要在mainwindow.yaml里添加自定义控件的引用(引用命名空间即可)
xmlns:ellis=“clr-namespace:WpfApplication.UserControlItems”