在XAML代码中导入名称空间

使用如下的代码导入指定的名称空间。不仅导入了名称空间,而且还为该名称空间指定了一个前缀local,当然也可以指定为其他的前缀名,这个可自行定义。导入后,该名称空间的公开成员即可在当前XAML代码中使用了。比如示例中的TimeButton这个类,其实是个继承自按钮的自定义控件类。

<Window x:Class="Demo002.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Demo002"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="Grid1">
        <Grid x:Name="Grid2">
            <Grid x:Name="Grid3">
                <StackPanel x:Name="StackPanel1">
                    <ListBox x:Name="ListBox1" />
                    <local:TimeButton x:Name="TimeButton1" Width="80" Height="80" 
                                      Content="Report Time" />
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</Window>


发布了359 篇原创文章 · 获赞 211 · 访问量 94万+

猜你喜欢

转载自blog.csdn.net/gjysk/article/details/38611169