首页 > 其他分享 >WPF ResourceDictionary ResourceDictionary.MergedDictionaries

WPF ResourceDictionary ResourceDictionary.MergedDictionaries

时间:2024-07-01 21:43:27浏览次数:1  
标签:resource dictionary ResourceDictionary WPF MergedDictionaries xaml

1.Add resource dictionary,Brushes.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <LinearGradientBrush EndPoint="1,0" x:Key="brush1">
        <GradientStop Color="Yellow" Offset="0"/>
        <GradientStop Color="Orange" Offset="0.7"/>
        <GradientStop Color="DarkRed" Offset="1"/>
    </LinearGradientBrush>
</ResourceDictionary>

 

2.In App.xaml

<Application x:Class="WpfApp186.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp186"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Brushes.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

3.MainWindow.xaml

<Window x:Class="WpfApp186.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:local="clr-namespace:WpfApp186"
        mc:Ignorable="d"  WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Ellipse Fill="{StaticResource brush1}"/>
    </Grid>
</Window>

 

 

 

 

 

 

标签:resource,dictionary,ResourceDictionary,WPF,MergedDictionaries,xaml
From: https://www.cnblogs.com/Fred1987/p/18278903

相关文章

  • WPF reference project
    //xaml<Windowx:Class="WpfApp1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.micr......
  • WPF在.NET9中的重大更新:Windows 11 主题
    在2023年的2月20日,在WPF的讨论区,WPF团队对路线的优先级发起了一次讨论。对三个事项发起了投票。第一个是Windows11主题第二个是更新的控件第三个是可空性注释最终Windows11主题得票最高,WPF团队2023-2024的工作优先级就是Windows11主题了。WPF控件的外观多年来一......
  • 界面组件DevExpress WPF v24.1 - 增强的可访问性 & UI自动化
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。DevExpressWPF控件日前正式发布了今年一个重大版......
  • WPF Rectangle ellipse
    <Windowx:Class="WpfApp185.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF TreeView 三层绑定模板
    在WPF应用程序中,使用TreeView来展示三层数据结构是一个常见的需求。为此,你需要定义适当的数据绑定和模板。以下是一个完整的示例代码,展示如何实现这一点。数据模型首先,我们需要定义三层数据模型。假设我们有三层数据结构:RootItem包含ChildItem,ChildItem又包含SubChildItem。pub......
  • WPF 做一个超级简单的 1024 数字接龙游戏
    这是一个我给自己做着玩的游戏,没有什么复杂的界面,就一些简单的逻辑游戏的规则十分简单,那就是有多个列表。程序会给出一个数字,玩家决定数字放在哪个列表里面。如果放入列表里面的数字和列表里面最后一个数字相同,那两个数字将会叠加进行合并,合并两个1024将会自动清理掉整个列表......
  • WPF中ComboBox几种数据绑定的方法
    一、用字典给ItemsSource赋值XMAL、<ComboBoxName="cmb_list"Grid.Row="1"Grid.Column="1"Height="23"DisplayMemberPath="Value"SelectedValuePath="Key"SelectionChanged="cmb1_SelectionChanged"......
  • WPF 视觉状态VisualState使用
    VisualState基本使用首先搭建一个自定义控件,继承自ContentControl,自动生成了这些文件由于CustomButton在Custom命名空间中,所以改一下xaml中的引用xmlns:local="clr-namespace:WpfApp1.Custom"定义部件和视觉状态TemplatePart是模板中的部件名TemplateVisualState是模板中......
  • WPF频繁更新UI卡顿问题
    我的WPF程序,需要连接PLC、CCD、RFID、扫码枪、控制卡所以我写了InitHardware();privatevoidInitHardware(){vartasks=newTask[]{//后台线程长连接,不取消令牌Task.Factory.StartNew(()=>InitConnPLC(),CancellationToken.None,Ta......
  • WebView2UI - 在WPF之中使用WebView2的一些经验总结
    项目地址:https://gitee.com/skyw18/WebView2UI项目地址:https://github.com/skyw18/WebView2UIwebview简介与生命周期:WPF应用中的WebView2入门-MicrosoftEdgeDeveloperdocumentation|MicrosoftLearn具体代码可以参考微软官方示例文档WPF示例应用-MicrosoftEdge......