in my WP7 app using silverlight controls,
I have two buttons,
I want to make when I press a button, the other button seems like it's also being pressed (change of color to invert...etc)
something like the native keyboard on wp7 phones when the larger button appear above your thumb
I tried to give both of them the focus, but it's not possible
-Detailed Explanation-
usually, when you press a button, the button style changes according to the theme,
ex: if theme is dark, the button becomes white and the text becomes black. but if the theme is white, the button becomes black when clicked.
My aim is to mimic that behavior to a button when another button is pressed.
In the click event you could use
VisualStateManager.GoToState(Button1, "Pressed", true);
however to go back to the Normal state you would have to know when the click is over. LeftMouseButtonUp does not work because there is no mouse.
So you could set a timer and revert the state. Ugly but it works.
On a side note: I suspect the design you might want to use a different way of getting the result you need.
I haven't done much wp7 development but I believe the normal, active and pressed appearances are implemented as different states of the button and you can programatically set the state. This article should explain it in a bit more detail but the advantage of this approach over manually setting background colours is that it should automatically take advantages of any transitions configured between those states, as well as the black => white, or white => black theme related changes will be done for you too.
http://www.timmykokke.com/2010/11/using-visual-states-in-custom-controls-in-silverlight/
Update:
In the click handler of one set the background property of the other.
In pseudo-code:
Button button1
ToggleButton button2
Button1.MouseDown:
Set button2 pressed state to true
Button2.MouseUp:
Set button2 pressed state to false
try using MS Expression Blend to customize the behavior, details
Related
I am trying to do something like X and O game, and I want the image of button be showed if it was pressed but it's not working, I made sure that button is working by reversing the command it worked fine! Here is screenshot
I tried to reverse the command and it worked so the button is working fine
Have in mind that a UI.Button requires at least one active and enabled visual component (Image/Text/etc) with RaycastTarget enabled ... I suspect since you disabled the image you simply disabled the interactions with this button
=> solution could be to simply have two Images like e.g.
- Button (with Button + Image component)
|-- Icon (with Image component)
The Button object is your main button with a background image - can be completely transparent, but can also react to interaction and have color for hover, press etc. This you always leave enabled and here you enable the RaycastTarget.
Then in Icon you assign the according circle or cross sprite and can enable / disable it accordingly. Here you can also deactivate the RaycastTarget to save some performance. You could even have two different child icons according to the sprites then you don't need to assign the sprite on runtime either but just activate according child object
Hi i am making a card inventory where i have 4 selected cards and a grid of cards to select from. when pressing a card i have a button that popps up that you can press to select the card, but my problem is that i have no clue how to make that button go away.
i want to have a select button show up when pressing a card, and pressing another will make it go away, or pressing anything else will make it go away. but i have no clue how to.
the dropdown ui template ha this built inn, when clicking the dropdown the options show up, when clicking anything else it goes away, i want that.
edit: for further clarification, i have 2 buttons, 1 makes the other one visable, the other one is going to go away when clicking anything else than the button itself. that is all i have
any idea random wonderful strangers on the internett
love
As I misunderstood your problem the first time, I'll write it the second time.
I think this is really simple to solve, so basically create a huge and transparent button which will detect all of the clicks besides from the cards and buttons.
So my solution is:
Create a button called for example "Background" and set its scale to an enormous values like 1000 to cover the whole screen all time.
Set all of the button's colors (Normal Color, Highlighted, Pressed, etc.) to transparent - basically set the Alpha value to 0
The button has to be above all of the other buttons in the Hierarchy of Canvas (or however you called it) in order to work as a background and not cover up other buttons.
Detect the clicks on the "Background", which will just hide the "Select" and the "Info" button.
I hope this time it will work.
I am creating a custom editor window in Unity. I want to have a label change color when the mouse hovers over it. To accomplish this, it would seem that this should work:
GUI.skin.label.hover.textColor = Color.red;
GUILayout.Label("My Label");
But the label still displays as normal with no effect when I hover over it with the mouse.
I've also tried manually creating GUIStyles and passing them as an argument to GUILayout.Label with the same result. If I change the normal state, however, I see the color change.
Is the hover state supported for labels, and if not, what controls is it supported for and how would I find out this information? It seems absent from Unity's docs.
You should be able to use GUI.skin.button if you are only interested in changing the text color.
var myStyle = new GUIStyle(GUI.skin.button);
myStyle.hover.textColor = Color.red;
GUILayout.Label("My Label", myStyle);
However, this has the side effect of taking all of the other qualities of the button style. Your label will look like a button. In theory you could change the background image for all of the style states and make it look not like a button, but doing so for the normal state reverts the hover behavior to that of a label style. This answer in the unity Q&A seems to be the most insightful explanation for why hover does not work (at least, not usually) but normal and active do.
In short, unity has special code for built in GUI styles that have hover over effects that force a redraw when the mouse passes over them. This seems to somehow be tied up in the normal style state for certain special styles, such as GUI.skin.button. The result, there is no option to have custom hover backgrounds, and anything that does need to have a custom hover text color must have the same background image as one of the built-in button styles.
I am currently trying to make a program where I have a picture of a calendar and when the user clicks on any given Friday a message box will appear. The current method I have been trying to do this is by placing a button over the dates, but I can't seem to find a way so that the button will be invisible and functional at the same time.
This is all in C# Windows Forms Application.
Any ideas?
There are several solutions:
Use an empty PictureBox instead of a Button. This is the nearest and quickest solution to what you say you want. Note that this secondary PictureBox needs to be a child of the calendar's one (with its background color set to Transparent). Transparency in Windows.Forms only applies to direct parents (it's more complex than this, but let's simplify).
Use the MouseUp event on the PictureBox where you are showing the calendar, and use the MouseEventArgs supplied as arguments to the event handler to find the X and Y position of the mouse within that control when the button was clicked.
Use a decent calendar/datepicker control instead of showing an image of one
Matter of fact: I don't endorse #1, and just put it there since it's what you seem to be asking for. I'd rather go with #2 or #3 (specially #3)
PS: if you want to really simulate Click, you should need to handle both MouseDown and MouseUp (a click usually means pressing a mouse button down on a control then releasing it within the same control)
I wonder how you can disable the buttonclick animation from a windows forms button. What I mean is, when you click on the button, it doesnt look like its being pressed, it just stays solid.
I dont want to change it to
button1.enabled = false;
as I still want it clickable and with colour.
Hope you understand what I am asking for, I searched through the properties of the button but I didnt find anything that seemed to work, maybe I missed something?
You must look into following:
FlatStyle property of button
Apply appropriate image for the button
After setting FlatStyle property, you can control appearance on mouse-over and mouse-down by looking into FlatAppearance property.