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.
Related
This may seem familiar to you but I have a problem creating a custom List Box with custom style as well. I can only do one of them at the same time... I can't use both. and another thing is that could you tell me how to add the custom listboxitem in c# code so I could easily add it to the program?
what I mean is that for example if you put an image before the text of listboxitem and then give it an style, but all thease must be done for all items.
thanks to all
First, what have you already tried out? Are you expecting SO users do the work for you?
Listbox tag has a ListboxItemTemplate. For that you can implement a DataTemplate has a StaticResource and put whatever you want inside.
Check the documentation on MSDN.
https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplate(v=vs.110).aspx
First of all, I'm new to XAML / C# (am iOS/Android programmer) so please bear with me instead of immediately voting down. My app has some GridViews that contain buttons. A lot of these buttons are similar and I would like to refactor this. For simplicity let's say my buttons are just Rectangles with a given color. This color might come from the Item class that defines the particular item in the GridView, or it might be hardcoded. I want the rectangle to change color on hover and pressed states. I want these colors to be parameters as well.
What is the best way to achieve this?
I tried to make a Button subclass but somehow I couldn't access the dependency properties in the VisualStateManager
I tried to write stuff in the code-behind but then I wasn't sure how to delegate the click command to the ViewModel class.
Could someone give me a small working example?
Thanks
You can do this with style templates.
In the Visual Studio designer, right-click on your button and then select Edit Template and then select Edit a Copy....
You will then be prompted to name your new style and also for which file to store it in. For now, just give it a unique name such as MyButtonStyle, and select the current file.
Visual Studio will then add a copy of the style to the current xaml document, and will update your button to use the new style.
<Button x:Name="Download" Style="{StaticResource MyButtonStyle}"></Button>
After this, you can update the new style including changing the colors for the different visual states such as hover or clicked.
You can then proceed to use the new style in other buttons in the same document. To use the style in multiple xaml documents, you have to pull it out into a common resource file.
So you want to adjust your button using custom properties. This is a good time to use a custom control. You can create whatever dependency properties you want and adjust your layout in your code. http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx
How can I make a custom button like in the image below? I searched on Google about custom control, but this is more special, is animated...
I know that on StackOoverflow are more questions like mine, but it is not a duplicate, I want to learn more about this particular button.
It is a button for WinForms.
you can create these buttons with GDI+ in C#,for example look at this one
On Windows form these buttons are made using the BackgroundImage Property of Button Control.
All you need is to toggle the background image on events like Click,OnMouseEnter etc.
This is not a custom control, this is CSS
Have a look at this, http://www.dynamicdrive.com/style/csslibrary/item/css_square_buttons/
You should possibly read something about gif-animation, jquery animation or css3 transitions to be able to animate backgrounds of such element
I'm trying to style some wpf user controls to make them look the same i have in my web application. I found some really great example for every control i need except for sliders and radio buttons.
Here is how they should look like:
Slider:
Radio Button:
I know i should create some ControlTemplate but i don't really know where to start...
If you can provide a complete example it would be perfect, but i guess that even some good deep advise would fit my needs.
Thank you 1000!
I have style sample here. It renders this:
I would start with Control Styles and Templates on MSDN pages. There are examples for most controls which give a good overview of how the control template works. Also you can extract/download the original control template and try to make your changes to it. Download default control templates
P.S. Actually the slider example on the first link resembles the one you describe.
Try using Expression Blend.
Learn Expression
and specifically this video: Creating ControlTemplates.
Expression Blend is something like a XAML design application - you can size, colour, adjust fill and stroke etc on all the elements in a control. It takes a little while to get used to, but you will be able to design controls with a graphical UI and Expression will provide you with the appropriate XAML to use in your project.
I am trying to develop a Customize TabControl in which I'll divide the Whole TabControl into three Parts:
1)Tab Header
2)Common Region(for all Tab) and
3)Tab Content region for specific Tab
Update:
Please provide your best answers or samples if you have then, any type of help will be appreciated.
Thanks in Advance
You can overwrite the TabControl Template to be anything you want, including making it have a static region that stays visible regardless of which tab is selected.
Within the Template, I normally use a panel with IsItemsHost=True to define where the "Tab" portion of the tab control will be displayed and <ContentPresenter ContentSource="SelectedContent" /> where I want the selected tab content to be displayed.
The TabControl.ItemTemplate can also be overwritten to further define your Tabs, and TabControl.ItemContainer can be overwritten to modify just the TabContent part of the TabControl.
Hmm ... I don't quite understand why one would do this, but if I were you I would implement this using WPF.
I would implement the tab header as a StackPanel filled with Buttons (their style obviously needs to be redone so that it looks like tabs). The content would be a rectangle containing a grid whose content changes on clicking a button. And that's pretty much it for the basic sceleton. I don't understand your Common Region. What is also nice is to add a little "X" inside each tab in order to close it. That can be done with buttons as well.
It might make sense to use Expression Blend to create such a control.
Best wishes,
Christian