中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

DynamicResourceをプログラムから設定したい

WPFネタですよと。

DynamicResourceはWPFのリソースと、依存プロパティを動的に結びつけ、リソースが変化したときに自動的に依存プロパティ側にも波及させます。

StaticResourceは作成時に1回だけ波及させます。

一般的な使い方

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
  <Window.Resources>
    <SolidColorBrush Color="Red" x:Key="br" />
  </Window.Resources>
    <Grid Background="{DynamicResource br}">
      <Button Margin="10" Click="bc"/>
    </Grid>
</Window>
        private void bc(object sender, RoutedEventArgs e)
        {
            Resources["br"] = new SolidColorBrush(Color.FromRgb(0, 0, 255));
        }

Gridの背景色をリソースから設定します。

それをボタンの処理で入れ替えているのがこのコードです。

んじゃこのDynamicResourceをコードからバインドするにはどうすればいいのか。

結構大変です。

 

ちょっとしらべるとDynamicResourceExtensionを使うというところにまでいきつき、豆司馬さんのところに行きつくわけですが。

http://d.hatena.ne.jp/shiba-yan/20080427/1209224429

というか、しばやんについったーでできるようん。って行ったから調べてたり(^^;;

でバインディングというか、リソース設定は以下のコードで可能

var dre = new DynamicResourceExtension("br");
gr.SetValue(BackgroundProperty, dre.ProvideValue(new ss()));

でこのssっていう適当なのがIServiceProvider, IProvideValueTargetをただ実装するだけです。

public class ss : IServiceProvider, IProvideValueTarget
{
	public object GetService(Type service)
	{
		if (service == typeof(IProvideValueTarget))
		{
			return this;
		}
		return null;
	}
	internal void SetData(object targetObject, object targetProperty)
	{
		TargetObject = targetObject;
		TargetProperty = targetProperty;
	}
	public object TargetObject { get; private set; }
	public object TargetProperty { get; private set; }
}

投稿日時 : 2008年6月3日 22:08

コメントを追加

# stromectol price in india http://stromectolabc.com/
stromectol 3 mg tablet 2022/02/08 3:23 Busjdhj

stromectol price in india http://stromectolabc.com/
stromectol 3 mg tablet

# stromectol xr http://stromectolabc.com/
ivermectin pills 2022/02/08 10:11 Busjdhj

stromectol xr http://stromectolabc.com/
ivermectin pills

# doxycycline tetracycline https://doxycyline1st.com/
doxycycline mono 2022/02/25 22:04 Doxycycline

doxycycline tetracycline https://doxycyline1st.com/
doxycycline mono

# generic for doxycycline https://doxycyline1st.com/
doxycycline tetracycline 2022/02/26 9:18 Doxycycline

generic for doxycycline https://doxycyline1st.com/
doxycycline tetracycline

# the best ed pills https://erectionpills.best/
male ed pills 2022/06/28 10:43 ErectionPills

the best ed pills https://erectionpills.best/
male ed pills

# antivirals for covid treatment https://paxlovid.best/
eua paxlovid 2022/09/07 22:33 Paxlovid

antivirals for covid treatment https://paxlovid.best/
eua paxlovid

# versandapotheke 2023/09/26 13:25 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
versandapotheke deutschland

# п»їonline apotheke 2023/09/26 23:10 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
versandapotheke deutschland

# online apotheke preisvergleich 2023/09/26 23:37 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
online apotheke gГ?nstig

# п»їonline apotheke 2023/09/27 0:59 Williamreomo

https://onlineapotheke.tech/# versandapotheke versandkostenfrei
online apotheke gГ?nstig

# п»їonline apotheke 2023/09/27 1:30 Williamreomo

https://onlineapotheke.tech/# online apotheke deutschland
online apotheke deutschland

# online apotheke gГјnstig 2023/09/27 2:59 Williamreomo

https://onlineapotheke.tech/# versandapotheke versandkostenfrei
versandapotheke

# gГјnstige online apotheke 2023/09/27 6:50 Williamreomo

http://onlineapotheke.tech/# online apotheke versandkostenfrei
internet apotheke

# п»їonline apotheke 2023/09/27 10:34 Williamreomo

http://onlineapotheke.tech/# п»?online apotheke
online apotheke gГ?nstig

# ed medication https://edpillsotc.store/# - treatment of ed 2023/10/08 5:01 EdPills

ed medication https://edpillsotc.store/# - treatment of ed

# order prescription from canada 2023/10/16 14:16 Dannyhealm

They simplify the complexities of international prescriptions. http://mexicanpharmonline.shop/# pharmacies in mexico that ship to usa

# canadian drug store 2023/10/16 14:55 Dannyhealm

Consistent excellence across continents. https://mexicanpharmonline.shop/# reputable mexican pharmacies online

# rx from canada 2023/10/16 18:08 Dannyhealm

A true asset to our neighborhood. http://mexicanpharmonline.com/# mexican mail order pharmacies

# canadian pharmacies online 2023/10/16 22:04 Dannyhealm

They have a great range of holistic health products. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# pharmacies online canada 2023/10/17 14:40 Dannyhealm

Their commitment to healthcare excellence is evident. https://mexicanpharmonline.shop/# pharmacies in mexico that ship to usa

# canada pharm 2023/10/18 3:07 Dannyhealm

Pharmacists who are passionate about what they do. http://mexicanpharmonline.shop/# mexican border pharmacies shipping to usa

# canada on line pharmacies 2023/10/18 12:23 Dannyhealm

Comprehensive side effect and adverse reaction information. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# best rated canadian pharmacies 2023/10/18 12:58 Dannyhealm

п»?Exceptional service every time! http://mexicanpharmonline.com/# mexican pharmaceuticals online

# canada rx prices 2023/10/18 15:17 Dannyhealm

They handle all the insurance paperwork seamlessly. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# canada mail order drug 2023/10/18 15:52 Dannyhealm

earch our drug database. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# top rated canadian pharmacies 2023/10/18 17:02 Dannyhealm

Their global reputation precedes them. http://mexicanpharmonline.com/# mexico drug stores pharmacies

# paxlovid pill https://paxlovid.bid/ paxlovid covid 2023/10/26 2:45 Paxlovid

paxlovid pill https://paxlovid.bid/ paxlovid covid

# paxlovid generic 2023/12/01 7:12 Mathewhip

paxlovid pill https://paxlovid.club/# paxlovid india

# farmacia online barata 2023/12/07 15:20 RonnieCag

https://vardenafilo.icu/# farmacia online madrid

# farmacia envíos internacionales 2023/12/08 3:55 RonnieCag

https://sildenafilo.store/# sildenafilo cinfa 100 mg precio farmacia

# farmacia barata 2023/12/08 6:57 RonnieCag

https://farmacia.best/# farmacia online barata

# farmacias baratas online envío gratis 2023/12/08 21:32 RonnieCag

https://sildenafilo.store/# sildenafil 100mg genérico

# farmacia online 24 horas 2023/12/09 13:00 RonnieCag

https://farmacia.best/# farmacia online madrid

# farmacia envíos internacionales 2023/12/09 19:20 RonnieCag

https://farmacia.best/# farmacias online seguras

# ï»¿farmacia online 2023/12/09 22:39 RonnieCag

http://farmacia.best/# farmacia envíos internacionales

# farmacia envíos internacionales 2023/12/10 12:05 RonnieCag

http://tadalafilo.pro/# farmacia envíos internacionales

# ï»¿farmacia online 2023/12/10 15:08 RonnieCag

https://sildenafilo.store/# sildenafilo 100mg precio farmacia

# farmacia 24h 2023/12/11 20:50 RonnieCag

https://vardenafilo.icu/# farmacia online barata

# farmacias baratas online envío gratis 2023/12/12 10:17 RonnieCag

http://vardenafilo.icu/# farmacias online seguras en españa

# farmacias online seguras en españa 2023/12/12 19:42 RonnieCag

http://sildenafilo.store/# sildenafilo precio farmacia

# farmacias online seguras en españa 2023/12/12 23:07 RonnieCag

https://sildenafilo.store/# sildenafilo 100mg precio farmacia

# farmacias baratas online envío gratis 2023/12/13 2:42 RonnieCag

http://tadalafilo.pro/# farmacias online seguras

# Pharmacie en ligne livraison rapide 2023/12/14 16:10 Larryedump

http://pharmacieenligne.guru/# Pharmacies en ligne certifiées

# Pharmacie en ligne France 2023/12/15 10:28 Larryedump

http://pharmacieenligne.guru/# acheter medicament a l etranger sans ordonnance

# Pharmacie en ligne sans ordonnance 2023/12/15 23:13 Larryedump

http://pharmacieenligne.guru/# acheter medicament a l etranger sans ordonnance

# Pharmacie en ligne livraison gratuite 2023/12/16 10:55 Larryedump

https://pharmacieenligne.guru/# Acheter médicaments sans ordonnance sur internet

# best ed drug https://edpills.tech/# cheap ed pills 2023/12/23 11:14 EdPills

best ed drug https://edpills.tech/# cheap ed pills

# can i order cheap clomid tablets 2023/12/26 19:55 RaymondGrido

http://clomid.site/# where can i buy clomid without rx

# paxlovid price 2023/12/29 8:56 Brianmooda

https://clomid.site/# how can i get generic clomid online

# buy doxycycline 100mg 2024/01/05 10:19 BobbyHef

http://cytotec.icu/# Misoprostol 200 mg buy online

# medications for ed 2024/01/10 4:02 CharlesDioky

http://sildenafildelivery.pro/# 100mg sildenafil generic

# natural ed medications 2024/01/10 10:46 CharlesDioky

https://edpillsdelivery.pro/# ed treatment review

# where can i buy cheap clomid price 2024/01/11 22:28 JeffreyRom

http://prednisone.auction/# prednisone 40 mg daily

# how to get clomid for sale 2024/01/12 14:33 JeffreyRom

https://clomid.auction/# where can i buy cheap clomid online

# acquisto farmaci con ricetta 2024/01/15 21:28 Walterpoume

https://tadalafilitalia.pro/# top farmacia online

# farmacie online autorizzate elenco 2024/01/15 22:24 Robertopramy

http://tadalafilitalia.pro/# farmaci senza ricetta elenco

# farmacia online più conveniente 2024/01/17 0:55 Wendellglaks

https://tadalafilitalia.pro/# farmacie online autorizzate elenco

# farmacia online senza ricetta 2024/01/17 6:40 Wendellglaks

http://tadalafilitalia.pro/# farmacia online migliore

# where can i buy cheap clomid without insurance 2024/01/21 21:10 LarryVoP

Every international delivery is prompt and secure https://cytotec.directory/# order cytotec online

# tamoxifen warning 2024/01/22 0:28 Normantug

https://prednisonepharm.store/# prednisone 5 mg tablet

# Acheter mГ©dicaments sans ordonnance sur internet 2024/01/28 12:19 AndresZot

https://pharmadoc.pro/# pharmacie ouverte 24/24
Acheter mГ©dicaments sans ordonnance sur internet

# ivermectin usa price 2024/01/29 23:11 Andrewamabs

https://prednisonetablets.shop/# prednisone 2 5 mg

# stromectol tablets 3 mg 2024/01/30 14:17 Andrewamabs

http://prednisonetablets.shop/# 30mg prednisone

# ivermectin lotion price 2024/01/31 14:51 Andrewamabs

https://prednisonetablets.shop/# prednisone 20mg

# prinzide zestoretic 2024/02/24 4:03 Charlesmax

http://furosemide.guru/# lasix generic

# dating chat free 2024/03/03 20:57 Thomasjax

http://angelawhite.pro/# Angela White izle

# dating best site 2024/03/05 7:53 Thomasjax

https://evaelfie.pro/# eva elfie izle

# free dating sites chat 2024/03/05 20:22 RodrigoGrany

https://abelladanger.online/# abella danger izle

# Abella Danger https://abelladanger.online/ Abella Danger
2024/03/06 12:06 Adella

Abella Danger https://abelladanger.online/ Abella Danger

# sweetie fox full https://sweetiefox.pro/ - sweetie fox full video
2024/03/06 23:33 SwitieFox

sweetie fox full https://sweetiefox.pro/ - sweetie fox full video

# danting site 2024/03/07 0:37 HowardBox

mature nl lesbian: https://evaelfie.site/# eva elfie hot

# jogo de aposta 2024/03/11 12:38 Robertcog

http://jogodeaposta.fun/# melhor jogo de aposta

# site de apostas 2024/03/12 8:32 Robertcog

http://aviatorghana.pro/# aviator sportybet ghana

# melhor jogo de aposta para ganhar dinheiro 2024/03/14 2:50 BrianTop

https://jogodeaposta.fun/# aviator jogo de aposta

# gates of olympus demo turkce oyna 2024/03/27 22:34 KeithNaf

http://sweetbonanza.bid/# sweet bonanza yasal site

# how to get generic clomid pills 2024/04/03 0:23 Robertsuela

http://clomidall.com/# cheap clomid without insurance

# how can i get cheap clomid price 2024/04/05 7:15 Robertsuela

http://clomidall.shop/# where can i buy generic clomid without insurance

# order cheap clomid now 2024/04/05 11:52 Robertsuela

https://clomidall.com/# cost of cheap clomid pills

# Tadalafil price 2024/04/08 0:43 JohnnieZet

https://tadalafiliq.shop/# Tadalafil price

# diflucan 200 2024/04/14 13:48 Josephfep

https://stromectola.top/# minocycline 50mg otc

# buy medications without prescriptions 2024/04/16 19:23 ArmandoWem

http://edpill.top/# order ed pills online

タイトル
名前
URL
コメント