static/dynamic resource

main
syneffort 2 years ago
parent 0f0a0b1074
commit e60506aaf7
  1. 6
      PacticeSolution/PacticeSolution.sln
  2. 9
      PacticeSolution/ResourceSample/App.xaml
  3. 17
      PacticeSolution/ResourceSample/App.xaml.cs
  4. 10
      PacticeSolution/ResourceSample/AssemblyInfo.cs
  5. 18
      PacticeSolution/ResourceSample/MainWindow.xaml
  6. 39
      PacticeSolution/ResourceSample/MainWindow.xaml.cs
  7. 10
      PacticeSolution/ResourceSample/ResourceSample.csproj

@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBindingSample", "DataBi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMSample", "MVVMSample\MVVMSample.csproj", "{FFD799B6-18C5-413B-8984-B44C803473B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceSample", "ResourceSample\ResourceSample.csproj", "{858EC308-9ABD-44C1-92E1-59911F60FEB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{FFD799B6-18C5-413B-8984-B44C803473B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFD799B6-18C5-413B-8984-B44C803473B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFD799B6-18C5-413B-8984-B44C803473B0}.Release|Any CPU.Build.0 = Release|Any CPU
{858EC308-9ABD-44C1-92E1-59911F60FEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{858EC308-9ABD-44C1-92E1-59911F60FEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{858EC308-9ABD-44C1-92E1-59911F60FEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{858EC308-9ABD-44C1-92E1-59911F60FEB9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,9 @@
<Application x:Class="ResourceSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ResourceSample"
StartupUri="MainWindow.xaml">
<Application.Resources>
<SolidColorBrush x:Key="CustomRed" Color="#e3533d"/>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ResourceSample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

@ -0,0 +1,18 @@
<Window x:Class="ResourceSample.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:ResourceSample"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="250">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button x:Name="btnStatic" Grid.Row="0" Height="50" Background="{StaticResource CustomRed}" Content="I'm Static Button!"/>
<Button x:Name="btnDynamic" Grid.Row="1" Height="50" Background="{DynamicResource CustomEventColor}" Content="I'm Dynamic Button!" Click="btnDynamic_Click"/>
</Grid>
</Window>

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ResourceSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
int _clickCount = 0;
private void btnDynamic_Click(object sender, RoutedEventArgs e)
{
if (_clickCount % 2 == 0)
this.Resources["CustomEventColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3de385"));
else
this.Resources["CustomEventColor"] = Resources["CustomRed"];
_clickCount++;
}
}
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
Loading…
Cancel
Save