解开XAML的邪恶面纱

什么是XAML,首先我们看下它的外观

<Window x:Class="Blend_WPF.WindowStyle"
        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:Blend_WPF"  mc:Ignorable="d" >
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="271,203.5,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window>

外一层是Window,进一层是Grid,再进一层是Button,感觉是和Web静态网页一样的写法,除了前面多了一些自己暂时还看不懂的xmlns

其实并不是,XAML官方定义是:一种相对简单、通用的声明式编程语言。所以别看这标签是这样,其实一个个对象(经过XAML编译器和运行时解析器解释后)

比如上面的一个Button

        <Button Content="Button" />

解开面纱,看本质

        Button b=new Button();

        b.Content="Button";

WPF通过XAML语言实现界面与逻辑分离,在一定程度上方便了开发人员和设计人员的分工协作,取得了不错的效果

猜你喜欢

转载自www.cnblogs.com/Kevinsh-Lee/p/9345733.html