How to change the look of a UserControl dynamically in Blend? - c#

I'm new to Blend and XAML, and I've got a UserControl containing just a white rounded off rectangle and a label with black text. However, when the UserControl is clicked, I want the rectangle to change to Blue and the label text to White, to emulate a sort of selected look. What is the best way to do this? I'm not familiar with XAML so I was hoping there'd be a solution where I can just set two templates for it in Blend, and then in that UserControl code window, have a click event handler where I just tell it to switch over to the other template. Thanks

The easiest - and designer friendliest - way to achieve this is to define two visual states. When the user clicks the control you can use the GotoStateAction to switch between the states.
Using visual states allows you to define everything visually without having to delve into code or XAML.
Hope it helps.

Related

Custom textbox style

I've made a custom textbox in Photoshop, and I want to apply it. I know, that you can't change the background in Visual Studio, or make it transparent. I've seen a few methods on how to do it, but they weren't very clear.
So I want to ask you - what is the esiest way to change the background of a textbox or make it transparent?
You need to Add a new user control , say CustomTextBox and Put this inside the constructor, which will make it transparent
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
C# transparency on textbox
Not sure about transparency, but changing the background of a text box is simple, check this link:
XAML:
http://www.c-sharpcorner.com/UploadFile/mahesh/XAMLTextBox04092007062405AM/XAMLTextBox.aspx
Also, if working on WinForms; you have the BackColor property that works in the same way:
http://msdn.microsoft.com/en-us/library/s2kh9x59(v=vs.110).aspx
EDIT:
You can do it by using a richtextbox instead... kind of.
http://www.codeproject.com/Articles/4544/Insert-Plain-Text-and-Images-into-RichTextBox-at-R
http://www.codeproject.com/Articles/12135/Inserting-images-into-a-RichTextBox-control-the-OL

Button Styles via xaml and expression blend

I created a custom control that looks a lot like the tab buttons in VS 2012. In my control I could set a propertiy to posistion the text and sidebar vertical or horizontal. After playing around with the control I figured there was probably a better way to go about this. So i fired up the Expression Blend preview and suprising enough (only second or third time using blend) was able to create a style to achieve a simliar style button. However, Now I want to have control over the text and sidebar being vertical or horizontal. I would also like to have control over the mouse over color. Is this possible to do via one style or am i going to have to create a bunch of different styles?
If I understood correctly you can achieve what you want to do with event triggers.

Docking buttons in the wpf panels

How can it be done? If there are, for example, four groups of buttons in menu-like panel. How would you dock them to their initial location if the window is resized?
I am trying this using DockPanel and HorizontalAlign, but it seems to only be work for the last button on the right when the window is resized. But how do you dock(anchor) a group of buttons? Maybe put them in border object and use HorizontalAlign for it? Is there more elegant way to do this?
To summarize the comments: I don't know your background but it seems you are used to another way of UI design where you do not explicitely have to specify grouping etc in code. While that might seem more elegant, it is not: the designer generated code is awful and the whole system is not as flexible nor srtaightforward as what WPF gives you..
With WPF you get a clear one-to-one relationship between your intent (treating buttons as a group within a layout) and the actual code (put the buttons in a stackpanel/grid/...). Or draw a border around buttons and organize them vertically within the border vs in xaml use a border with a stackpanel inside. It won't get any more elegant than that.
Read up on WPF layouts and once you'll get a grip of it you will quickly see that it is rather powerful and beatiful at the same time. I found this tutorial pretty helpful when just starting with layouts. And google provides lots and lots and lots more information, as usual.
Like stijn said, put the buttons in a Grid or a Stackpanel and you'll be fine.
You may not think it's beautifull, but it's the best solution for your problem.

Looking for suggestions on how to create an enhanced tooltip

currently I am using a tool tip to display information when it hovers over a region on a winform. This works well and I don't have any complaints, but the boss want's to display more complex data, that would best be displayed in a grid rather than text.
Is there a way that perhaps I could embed a usercontrol or a datagridview in a tool tip.
thanks
C#, .Net 2.0, windows.Forms
There's such a thing as an owner-drawn tooltip. You'd have to handle the painting of the grid yourself. You wouldn't get any interactivity, although a tooltip that lets you click and scroll sounds odd anyway.
If your boss is willing to spend money on this then I can happily recommend the DevExpress tooltip control, for its customisability.
You can write a custom control (shouldn't be too hard, just a yellow rectangle with a drop shadow) with a data grid on it. It just needs to fade out when the mouse moves away and get displayed after the mouse rests on it for a couple of seconds.

Is it possible to get your user control to display those alignment guides when placing them on a WinForm?

In Visual Studio (2008) when you place a textbox on a Windows Form, and drag it around, you see very helpful guidelines which help you align it (left, right, top or bottom) to other controls. You also see a line the represents the bottom of the text in that control helping you align the text within your textbox, to the text within a label, regardless of the height of that label.
I have user control that contains a textbox and a couple of buttons. Can I force the VS2008 designer to show me the same line for the bottom of the text, from the textbox within my user control? If so, how?
Seems like this answer might be what you need - Baseline snaplines in custom Winforms controls

Categories

Resources