Slider and radio button styling in wpf - c#

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.

Related

Custom control creating

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

Drawing custom TextBox Controls

I found this code here which explains how to create custom controls. I have been using these controls as buttons, but now that I am beginning to understand the code a bit more, I would like to try and create a text box control using the same drawing techniques. I have been searching endlessly for some examples on the subject, but cannot find a single one. I don't understand how a textbox can be writable if a rectangle is being used to make it. Does anybody have any experience creating custom controls in C#? I would like for my textbox to be able to match the theme in the above link which is why it has to be custom made.
Well, at the beginning you should have in mind, that the implementation of new text box control is kinda complicate thing. It is necessary that you consider the following points:
1) What should your textbox do? How can the user interact with it? Which events do you necessarely throw?
2) How should you textbox be drawn? Is it a simple box with an outline or do you have elements which are different if the user gets interacted.
A good starting point for implementing your own textbox is to look how it works under the hood - in fact, you should start by referencing to samples which came from the DirectX and DirectDrawing area, one example is the following link (the sample is for c++, but the concepts are the same as used in windowsforms or wpf drawing):
http://www.uc-forum.com/forum/d3d-tutorials-and-source/65377-make-textbox-ingame-console-directx.html
a more direct sample (explaining howto extend an existing textbox) can be found here:
http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/
All in all, to achieve your goal try to extend the basic text box at the beginning and afterwards start with a component which is not that complicated, for example a simple checkbox. Go on and at the end you will be able to implement your own textbox control ;)

Creating a reusable interface element in WPF

I'm developing a WPF application in C# and was thinking about implementing a custom UI element accross various windows.
I would like to have a minimized tray (only about 4px visible) that expands after clicking on an icon next to the tray. The expanded version would show all controls and would minimize when I click the icon again. I created a quick HTML concept to clarify things.
I know I could put a stackpanel and button in my application and making both of them move up when I click the button, but then I would need to duplicate the code a lot.
Though I'm experienced with C#, I'm fairly new to WPF interface development/templates, but I'm sure there has to be a way so I can use that UI element accross my application without needing to copy/paste a lot of lines of code in my form class file.
I hope someone can help me, or at least point me in the right direction.
There are three ways to customize your elements.
1 If you only need visual modifications you can use styles to change the appearance of the .net default controls. You can even override / extend the default templates.
2 If you want custom logic in a control you can create a custom control. The framework brings a lot of "primitives" to build upon. Examples are ContentControl or HeaderedContentControl. Say you want to build a custom expander control you can inherit your custom control from HeaderedContentControl which provides you with Header and Content properties and you just have to implement the toggling logic yourself.
CustomControls are a good choice if you want to build basic functionality which can be used throughout your application. They can be themed/styled depending on the use case, too (see 1).
3 If you want to compose different controls into one control you can create a UserControl. User controls are composed using XAML. Most top level controls are user controls driven by a view model.
Your case can be build using a Popup and ToggleButton or an Expander.
The decision depends on the desired behavior. If you want the opened panel to move following content down you need a expander. If you want a dropdown like functionality you need popup.
If you use a popup just bind the IsPopupOpen Property to IsChecked of the ToggleButton and set PopupStaysOpen = false to wire the button to your popup.
If you use an expander control you should create a style which can be applied to all equal expanders in your application to minimize the required XAML in each view.
How about using Expander Control?
There's a control called an Expander that is perfect for this. You'll have to style it to look like you want, however it has the functionality you want built-in.

Silverlight: Custom Radio button

I am trying to develop a custom radio button that looks like a two-option button control that looks somewhat as shown below with toggling of highlighted state. Not sure where to start.
Is there any such controls already available that I can use.
OK, here is a brief overview of what you will need to do ...
Firstly, you will need to change the ControlTemplate for the existing RadioButton control. There are lots of tutorials available that describe this,, for example this one.
Replace the standard template with some suitable markup for your illustration above. Perhaps a two column Grid?
Within each Grid cell add a Rectangle, one behind Option1, and the other behind Option2
Use the VisualStateManager to change the Fill property of each Rectangle based on the controls current VisualState. i.e. when Pressed toggle the background colours.
The steps above should help you achieve your goal. Please read the linked web pages and the Silverlight documentation. If you are still struggling after that,, come back and ask another question.

How can I change the default Control template of a TabControl according to my choice

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

Categories