开发者

Windows Phone, dynamic style

开发者 https://www.devze.com 2023-02-21 22:10 出处:网络
I\'m working on an app where I want the color of a few borders to change depending on the users choice of theme. The borders are partly placed in the xaml, but also dynamically generated throughout th

I'm working on an app where I want the color of a few borders to change depending on the users choice of theme. The borders are partly placed in the xaml, but also dynamically generated throughout the app depending on choices the user make. I am also using a few LoopingSelector controls (from the Silverlight toolkit), that in turn also generate borders.

So, I was wondering how I should approach this problem. Initially I tried applying a style to the borders, and then changing the style depending on the choice of theme, but apparently styles are read-only during run time. I also figured I could iterate through and change the color of the borders, but it seems the LoopingSelector doesn't expose that property of its borders, or really, expose the controls at all.

So I assume I should use binding in some way, but as I'm still quite new to Silverlight I'm not really su开发者_Python百科re how to go about that.

Thanks in advance.


If you have a named resource, say CustomBorderBrush, that you are using in your XAML for the parts that are in the XAML, then you can access this brush from the Application's resources:

Border newBorder = new Border();
newBorder.BorderBrush = (Brush)Application.Current.Resources["CustomBorderBrush"];

If you additionally have a problem with the LoopingSelector, then that's a separate issue :) It sounds like you need to apply your own style to the LoopingSelector so that you can specify the brush value that you need.

0

精彩评论

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