Load Image to a button by Code behind(C#) in WP7
Being a beg. me facing a problem. Please help me out.
I have created a "Style" in xaml and named it "CustomButton" for creating a button( which consist of Two Images and one Textblock) and want to load one of the image and text开发者_运维知识库 to TextBlock only at runtime i.e by code behind so that ill be having diffrent image and differnt text for each button. Actully, me need create an array of Buttons of the same style but diff. Image.
Style mystyle = (Style)Application.Current.Resources["CustomButton"];
Setter templateSetter = (Setter)mystyle.Setters[0];
btnNext.Style = mystyle;
i created "style" in App.xaml and in code behind i call name style.
hope this help !
Thongaduka !
Depending how much XAML you want, you need to either create a custom UserControl that inherits from Button, with a DependencyProperty for the background.
Or you can specify a ImageBrush for the Background property, and use that, along with the Content property, in your custom style. The ImageBrush approach is going to require some 3-4 lines of XAML per button.
And I wouldn't recommend creating any UI controls from C#, as you can do everything you want to using databindings. If you're attempting to render custom buttons inside a listbox, with a custom background, simple databinding work should do just fine, rather than creating any custom controls or styles.
Feel free to clarify (with code!) what you're attempting to do now.
精彩评论