• WPF使用其他命名空间中的类型


    为使用未在WPF命名空间中定义的类,需要把.net命名空间映射 到一个XML命名空间

    XAML有一个特殊的语法可用于完成这一工作。

    语法:

    xmlns:prefix="clr-namespace:Namespace;assembly=AssemblyName"

    prefix:是希望在XAML标记中用于指示命名空间的XML前缀。例如,XAML语言使用的x前缀。通常情况下,使用.net中其他的类型,前缀使用sys,而使用当前项目中的类型,前缀会使用local命名。

    Namespace:是完全限定的.net命名空间的名称。

    AssemblyName:是声明类型的程序集,没有.dll扩展名。这个程序集必须在项目中引用。如果希望使用项目程序集,则可以忽略这一部分。

    实例:


    <Window x:Class="MyWPF._2_4使用其他命名空间中的类型"
            xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:sys
    ="clr-namespace:System;assembly=mscorlib"
            Title
    ="_2_4使用其他命名空间中的类型" Height="300" Width="300">
        <Grid>
            <ListBox>
                <ListBoxItem>
                    <sys:DateTime>10/13/2010 4:30</sys:DateTime>
                </ListBoxItem>
                <ListBoxItem>
                    <sys:DateTime>10/13/2010 4:30</sys:DateTime>
                </ListBoxItem>
                <ListBoxItem>
                    <sys:DateTime>10/13/2010 4:30</sys:DateTime>
                </ListBoxItem>
                <ListBoxItem>
                    <sys:DateTime>10/13/2010 4:30</sys:DateTime>
                </ListBoxItem>
            </ListBox>
        </Grid>
    </Window>
  • 相关阅读:
    python发送邮件
    nginx的信号量和平滑升级
    CentOS6下nginx的源码安装
    mysql备份与还原之mysqldump
    myslq基本语法(3)
    mysql基本语法(2)
    MySQL中数据表和数据的操作
    mysql概述及基本语法(1)
    shell的随机数
    浏览器的跨域问题的解决办法
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2691675.html
Copyright © 2020-2023  润新知