0
点赞
收藏
分享

微信扫一扫

XAML练习,资源字典,静态资源,动态资源,绑定

奔跑的酆 2022-01-12 阅读 53
c#

字典:

<ResourceDictionary 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" xmlns:local="clr-namespace:Zhaoxi.ResourceStudy">
 

    <SolidColorBrush x:Key="color">green</SolidColorBrush>
    <sys:String x:Key="text">ZG,WPF</sys:String>
    <local:Person Name="ZG" Age="33" x:Key="personZG"/>
    <ImageBrush ImageSource="/Images/Logo.png" x:Key="image"/>

</ResourceDictionary>

主窗体

<Window
    x:Class="Zhaoxi.ResourceStudy.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:local="clr-namespace:Zhaoxi.ResourceStudy"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Window.Resources>
        <ResourceDictionary Source="DefaultDictionary.xaml">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <SolidColorBrush x:Key="color3">orange</SolidColorBrush>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        
    </Window.Resources>
    
    
    <Grid x:Name="grid" DataContext="{StaticResource personZG}">
        <Grid.Resources>
            <SolidColorBrush x:Key="color1">blue</SolidColorBrush>
        </Grid.Resources>
        <StackPanel>
            <TextBlock Text="{StaticResource text}" FontSize="40"/>
            <TextBlock Text="{Binding Name}" FontSize="40"/>
            <TextBlock Text="{Binding Age}" FontSize="40"/>
            <Border Width="100" Height="100" Background="{StaticResource image}" BorderBrush="red"/>

            <!--  Image Name="img" Source="/Images/Logo.png"/  -->
        </StackPanel>

    </Grid>
</Window>

举报

相关推荐

0 条评论