<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C# WPF 資源字典

      1、在Window.Resources中聲明

      注意:這種方式聲明的資源只能在當(dāng)前Window中使用。


      1)在Xaml中使用:

       

      <Window x:Class="WpfApp_Test.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:WpfApp_Test"
              mc:Ignorable="d"
              Title="MainWindow" Height="240" Width="300">
          <Window.Resources>
              <ResourceDictionary>
                  <Style TargetType="TextBlock" >
                      <Setter Property="FontStyle" Value="Italic"/>
                      <Setter Property="FontWeight" Value="Bold"/>
                      <Setter Property="Foreground" Value="Red"/>
                  </Style>
                  <Style x:Key="textBlockStyle" TargetType="TextBlock" >
                      <Setter Property="Foreground" Value="Green"/>
                  </Style>
              </ResourceDictionary>
          </Window.Resources>
          <StackPanel>
              <TextBlock  Text="Hello"/>
              <TextBlock  Text="Hello" Style="{StaticResource textBlockStyle}"/>
              <TextBlock  Text="Hello" Style="{x:Null}"/>
          </StackPanel>
      </Window>

       

       

       

      運行效果:

       

       

      2)在后臺代碼中使用:

      <Window x:Class="WpfApp_Test.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:WpfApp_Test"
              mc:Ignorable="d"
              Title="MainWindow" Height="240" Width="300">
          <Window.Resources>
              <ResourceDictionary>
                  <Style TargetType="TextBlock" x:Key="TextBlockStyle">
                      <Setter Property="FontStyle" Value="Italic"/>
                      <Setter Property="FontWeight" Value="Bold"/>
                      <Setter Property="Foreground" Value="Red"/>
                  </Style>
              </ResourceDictionary>
          </Window.Resources>
          <StackPanel>
              <TextBlock x:Name="textBlock1" Text="Hello"/>
              <TextBlock x:Name="textBlock2" Text="Hello"/>
              <TextBlock x:Name="textBlock3" Text="Hello"/>
          </StackPanel>
      </Window>
      
      
      public partial class MainWindow 
      {         
          public MainWindow()
          {
              InitializeComponent();
              Style style = (Style)this.FindResource("TextBlockStyle");  //搜索
           //如果明確知道資源放在哪里,則可以使用
           //Style style = (Style)this.Resources["TextBlockStyle"]; textBlock1.Style
      = style; } }

      運行效果:

       2、在App.xaml中聲明(全局可用)

      <Application
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:local="clr-namespace:WpfApp_Test"
                   xmlns:av="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="av" x:Class="WpfApp_Test.App"
                   StartupUri="MainWindow.xaml">
          <Application.Resources>
              <ResourceDictionary>
                  <Style TargetType="TextBlock" >
                      <Setter Property="FontStyle" Value="Italic"/>
                      <Setter Property="FontWeight" Value="Bold"/>
                      <Setter Property="Foreground" Value="Red"/>
                  </Style>
                  <Style x:Key="textBlockStyle" TargetType="TextBlock" >
                      <Setter Property="Foreground" Value="Green"/>
                  </Style>
              </ResourceDictionary>
       
          </Application.Resources>
      </Application>
      
      
      <Window x:Class="WpfApp_Test.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:WpfApp_Test"
              mc:Ignorable="d"
              Title="MainWindow" Height="240" Width="300">    
          <StackPanel>
              <TextBlock  Text="Hello"/>
              <TextBlock  Text="Hello" Style="{StaticResource textBlockStyle}"/>
              <TextBlock  Text="Hello" />
          </StackPanel>
      </Window>

      運行效果:

       3、在資源字典文件中聲明:

      添加資源字典文件的方式,先在項目中新建一個文件夾Resources(也可以不用建文件夾),然后點擊右鍵-——Add——Resource Dictionary(WPF)。 然后把資源添加進去。

       

      //TextBlockStyle.xaml:資源字典文件
      <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
          <Style TargetType="TextBlock" >
              <Setter Property="FontStyle" Value="Italic"/>
              <Setter Property="FontWeight" Value="Bold"/>
              <Setter Property="Foreground" Value="Red"/>
          </Style>
          <Style x:Key="textBlockStyle" TargetType="TextBlock" >
              <Setter Property="Foreground" Value="Green"/>
          </Style>
      </ResourceDictionary>
      
      
      //App.xaml
      <Application
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:local="clr-namespace:WpfApp_Test"
                   xmlns:av="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="av" x:Class="WpfApp_Test.App"
                   StartupUri="MainWindow.xaml">
          <Application.Resources>
              <ResourceDictionary>
                  <ResourceDictionary.MergedDictionaries>
                      <ResourceDictionary Source="Resources/TextBlockStyle.xaml"/>  
             //或者<ResourceDictionary Source="/WpfApp_Test;component/Resources/TextBlockStyle.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> //MainWindow.xaml <Window x:Class="WpfApp_Test.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:WpfApp_Test" mc:Ignorable="d" Title="MainWindow" Height="240" Width="300"> <StackPanel> <TextBlock Text="Hello"/> <TextBlock Text="Hello" Style="{StaticResource textBlockStyle}"/> <TextBlock Text="Hello" /> </StackPanel> </Window>

       最簡單的就是直接寫文件路徑

      <ResourceDictionary Source="Resources/TextBlockStyle.xaml"/>

       

      注:Style 可以通過BaseOn繼承其他Style

      //資源字典文件
      <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
          <Style TargetType="TextBlock" >
              <Setter Property="FontStyle" Value="Italic"/>
              <Setter Property="FontWeight" Value="Bold"/>        
          </Style>
          <Style x:Key="textBlockStyleGreen" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
              <Setter Property="Foreground" Value="Green"/>
          </Style>
          <Style x:Key="textBlockStyleRed" TargetType="TextBlock" >
              <Setter Property="Foreground" Value="Red"/>
          </Style>
      </ResourceDictionary>
      
      
      <Window x:Class="WpfApp_Test.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:WpfApp_Test"
              mc:Ignorable="d"
              Title="MainWindow" Height="240" Width="300">    
          <StackPanel>
              <TextBlock  Text="Hello"/>
              <TextBlock  Text="Hello" Style="{StaticResource textBlockStyleGreen}"/>
              <TextBlock  Text="Hello" Style="{StaticResource textBlockStyleRed}"/>
          </StackPanel>
      </Window>

      運行效果:

       

      如果資源有key的話,也可以通過key來繼承:

       

      注意:TargetType可以直接寫類型名:

       也可以通過x:Type來寫

       

      posted @ 2025-06-18 21:25  竹樓風(fēng)雨聲  閱讀(42)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 在线看国产精品自拍内射| 成人午夜大片免费看爽爽爽| 四虎永久精品在线视频| 国产视频一区二区| 中文字幕av一区| 国产午夜福利免费入口| 暖暖视频日本在线观看| 亚洲伊人精品久视频国产| 加勒比中文字幕无码一区| 日本阿v片在线播放免费| 欧美肥老太wbwbwbb| 不卡乱辈伦在线看中文字幕| 日本中文字幕在线播放| 99精品久久精品| 成年女人免费碰碰视频| 国产乱码1卡二卡3卡四卡5| 亚洲人成人网站色www| 亚洲av色综合久久综合| 精品国产乱子伦一区二区三区| 亚洲人成小说网站色在线| 97亚洲熟妇自偷自拍另类图片| 1精品啪国产在线观看免费牛牛| 久久精品国产成人午夜福利| 国产精品制服丝袜无码| 国产另类ts人妖一区二区| 江华| 国产精品久久久久鬼色| 久久国产精品乱子乱精品| 性色av无码久久一区二区三区| 午夜福利日本一区二区无码| 亚洲精品一二三在线观看| 中文www天堂| 永久免费无码av在线网站| 青青热在线精品视频免费观看| 在线a亚洲老鸭窝天堂| 日本大片在线看黄a∨免费| 国产精品久久久久aaaa| 欧美大胆老熟妇乱子伦视频| 欧美高清一区三区在线专区| 精品国产一区二区三区香| 乱60一70归性欧老妇|