Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to bind a setter property value with a variable in WPF from one window to another?
I have this Code :
XML
<Style x:Key="Style1" TargetType="Button">
<Setter Property="Background" >
                <Setter.Value>
                    <SolidColorBrush Color=" COLORHERE "></SolidColorBrush>
                </Setter.Value>
..........
I want to bind the color with a variable in another window to change the color for all buttons at runtime. I am coding in VB.NET

XML
<Thanks All="Very Much"> :D
Posted
Updated 18-Jan-13 11:39am
v3
Comments
Sergey Alexandrovich Kryukov 18-Jan-13 16:42pm    
So, is if Forms or WPF?! There are different libraries. You either use one or another. (This is also interop, but I think we don't discuss this pathology only applicable to using some legacy code.)
—SA
Abed AlSayed 18-Jan-13 17:18pm    
WPF, it maybe an easy solution for my question, but I am new to WPF, you told me that WPF is faster than winForm on my other account(abdallah alsayed) Here : (http://www.codeproject.com/Questions/523226/Howplustoplusspeedplusupplusmyplusvb-netplusapplic) and U were right. My Project (GIF animator) is pretty fast even if the used Picture is larger than 54 MB, My language is not English so I don't really know what words to use in my questions, but I meant that I want to change the "Style1" background Property at runtime using a vb.net code, then when the style background changed the buttons background will change too, I'm I wrong? Thanks
Sergey Alexandrovich Kryukov 18-Jan-13 17:25pm    
That's not English, this is just the terminology you need to be aware of. WPF does not have the class named "Form". There is System.Windows.Forms.Form class, but this is a different library. In WPF, you normally use the class "Window" instead of that.

The tag "Forms" in your tag is what we use, but in your case please remove it, to avoid further confusions. You are the most interested in that. Other tags are fine.

—SA

P.S.: I'm sorry, I'm not 100% sure what happens with the child background when you change this style (I would guess not), did not do if for a while. But wouldn't it be easier for you just to find out by trying it? :-)
Abed AlSayed 18-Jan-13 17:36pm    
Sorry I'll be careful the next time I ask. ' But wouldn't it be easier for you just to find out by trying it?' >>> I wouldn't ask if I know what vb.net code should I use to edit a setter.value at runtime and try it :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900