wpf添加资源字典(xaml)

wpf添加资源字典(xaml)
拖鞋生产设备
Wpf添加资源字典
1.新建⼀个字典,设置好名称空间,key,TargetType等。
例如添加⼀个ListBox的资源字典
<ResourceDictionary xmlns="schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfMyDemo">
<Style x:Key="ViewInfoStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Height="35" x:Name="grid">
安全绳网<!--<Border Background="{Binding UserBackground}" Width="40" Height="40" CornerRadius="4" HorizontalAlignment="Left" Margin="5 0 0 0">
<TextBlock Text="{Binding Header}" FontSize="23" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<TextBlock Text="{Binding Name}" Margin="55 7 0 0" FontSize="13"/>
<TextBlock Text="{Binding Info}" Foreground="#808080" Margin="55 30 0 0"/>
<TextBlock Text="{Binding Count,StringFormat={}{0}⼈}" Foreground="#808080" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0 0 5 0"/>-->                        <CheckBox Width="20" IsChecked="{Binding IsSelection}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Side}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15"/>
<TextBlock Text="{Binding Count,StringFormat={}{0}Axis}"  VerticalAlignment="Center" FontSize="15" HorizontalAlignment="Right"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="grid" Property="Background" Value="#fceeb9"/>
</Trigger>
<Trigger Property="Selector.IsSelected" Value="true">
<Setter TargetName="grid" Property="Background" Value="#fae388"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
2.在App.xaml中声明资源字典
耐老化测试<Application x:Class="WpfMyDemo.App"
xmlns="schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfMyDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfMyDemo;component/Styles/TabControl.xaml"/>
免火再煮锅
<ResourceDictionary Source="pack://application:,,,/WpfMyDemo;component/Styles/ListBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>林妙可被毒虫咬伤
</Application.Resources>
</Application>
3.在MainWindow中添加相应的控件,引⽤创建的资源字典,根据key
ListBox VerticalAlignment="Top"  BorderThickness="1" ItemContainerStyle="{StaticResource ViewInfoStyle}" x:Name="ViewInfoListBox" BorderBrush="#eaeaeb"
Background="#FF3A3831" Height="220" Margin="0,30,0,0" >
驳接头</ListBox>

本文发布于:2024-09-21 11:01:35,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/286595.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:字典   资源   添加   设备   毒虫   生产   咬伤
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议