Android xml has a nice thing for button (and other things) states which are selectors.
Here is an example of the Android Documentation:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize=["true" | "false"]
android:dither=["true" | "false"]
android:variablePadding=["true" | "false"] >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
Is there something in XAML or C# we can use to obtain the same effect on Windows (Phone) apps. (Or Universal Apps for that matter).
Nowadays I use the Listeners GotFocus, LostFocus, etc. But i don't think it is a straghtforward solution.
Anyone has a better idea on how to do this?
You can define a complete multi-state layout of a control purely in xaml. Define a custom style for button and set the Template
property. Unfortunately this completely overrides the template, so you would probably have to copy the default one. There you can set different VisualStates
for Pressed
, MouseOver
etc.
To get the button default style use Blend as described here: http://www.geekchamp.com/tips/windows-phone-button-default-style
More info on custom button templates: http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-button
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.