WPF 命名空间

1、项目默认创建之后会有一个本地的命名空间引入

xmlns:local="clr-namespace:studywpf"

2、引入命名空间的格式:

     

xmlns:前缀="clr-namespace:命名空间"

3、本地使用local 前缀、如果使用系统的则使用 sys前缀。引入示例之后就可以使用命名空间内的类创建对象和控件等等

4、基本引入示例:

<Window x:Class="studywpf.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:sys ="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:studywpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
       
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" 
                 x:Name="txtQuestion" Grid.Row="0"
                 TextWrapping="Wrap" FontFamily="Verdana" FontSize="24"></TextBox>
        <Button VerticalAlignment="Top" HorizontalAlignment="Left"   Margin="10,0,0,20"
                Width="127" Height="23" x:Name="cmdAnswer" Click="cmdAnswer_Click" Grid.Row="1" Content="Ask thr Eight Ball"></Button>
        <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtAnswer"
                 TextWrapping="Wrap" IsReadOnly="True" FontFamily="Verdana" FontSize="24" Foreground="Green"
                 Grid.Row="2"></TextBox>
        <ListBox Grid.Row="2">
            <ListBoxItem>
                <sys:DateTime>10/11/2013</sys:DateTime>
            </ListBoxItem>
            <ListBoxItem>
                <sys:DateTime>10/11/2013</sys:DateTime>
            </ListBoxItem>
        </ListBox>

        <Grid.Background>
            <LinearGradientBrush>
                <LinearGradientBrush.GradientStops>
                    <GradientStop Offset="0.00" Color="Red"/>
                    <GradientStop Offset="0.50" Color="Indigo" />
                    <GradientStop Offset="1.00" Color="Violet" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Grid.Background>

    </Grid>
</Window>

上例中: 引入sys前缀的datetime 命名空间:使用示例为:

  <ListBox Grid.Row="2">
            <ListBoxItem>
                <sys:DateTime>10/11/2013</sys:DateTime>
            </ListBoxItem>
            <ListBoxItem>
                <sys:DateTime>10/11/2013</sys:DateTime>
            </ListBoxItem>
        </ListBox>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值