欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf 中如何引用自定义控件

程序员文章站 2022-03-04 11:13:02
...

wpf 中如何引用自定义控件
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”

相关标签: WPF