开发者

Get DynamicResource Binding in WPF

开发者 https://www.devze.com 2022-12-11 04:17 出处:网络
Can any one help me to get DynamicResource Binding in WPF by code? I have set binding Like follow,开发者_Python百科

Can any one help me to get DynamicResource Binding in WPF by code?

I have set binding Like follow,

开发者_Python百科

TextBlock Background={DynamicResource ColorA} Name="TB" in Xaml.

and i need to get the - TB's background is binded to "ColorA". how can i access this DynamicResource Binding Expression in WPF by coding. when i try to get TB.Background, it is white(#FFFFF..) or if i already given the value to the Resorce key "ColorA" that will be given. but i want to get this Binding Expression. Thank in advance for your Help.


I think my Question wasn't clear. I want to get What Reource Binding was done to the "TB" in Xaml by code. But the aren't any TB.GetResourceReference. I Want some think like that. Where that Binding expression is kept in WPF. I need to get the TB's BackgroundProperty was Binded to Which( answer "ColorA") key? thank a lot for sudden response.


You can use the FrameworkElement.SetResourceReference method:

MSDN: http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.setresourcereference.aspx

Provided your xaml has this:

<TextBlock x:Name="TB">

You can write this in the code behind:

TB.SetResourceReference(BackgroundProperty, "ColorA");


You can use this:

YourControl.Style = this.FindResource(NameOfYourStyleForThisControl) as Style;
0

精彩评论

暂无评论...
验证码 换一张
取 消