zoukankan      html  css  js  c++  java
  • WPF -- 一种添加静态资源的方式

    本文介绍使用独立的xaml文件添加静态资源的方式。

    步骤
    1. 创建XAML文件,如ImageButton.xaml,添加ResourceDictionary标签,并添加静态资源;
    2. 在App.xaml的Application.Resources标签中添加xaml资源文件;
    3. 在xaml界面文件中使用StaticResource使用静态资源。
    示例
    // ImageButton.xaml
    <ResourceDictionary xmlns...>
        <Style x:Key="CustomImageButton" TargetType="Button">
            ...
        </Style>
    </ResourceDictionary>
    
    // App.xaml
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/WpfApplication1;component/CustomControls/ImageButton.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
    // 使用ImageButton的xaml
    <StackPanel>
        <Button Width="50" Height="30" Content="Button" FontSize="14" Style="{StaticResource CustomImageButton}" />
    </StackPanel>
    
    转载请注明出处,欢迎交流。
  • 相关阅读:
    2021 发工资咯:)
    HDU-2021
    HDU-2020
    HDU-2019
    HDU-2018
    HDU-2017
    HDU-2016
    HDU-2015
    HDU-2014
    HDU-2013
  • 原文地址:https://www.cnblogs.com/louzixl/p/14297230.html
Copyright © 2011-2022 走看看