简体   繁体   English

Windows(电话)是否具有与Android选择器相当的功能?

[英]Is there a Windows (Phone) equivalent of the Android selector?

Android xml has a nice thing for button (and other things) states which are selectors. Android xml对于按钮状态(和其他状态)是选择器来说是一件好事。

Here is an example of the Android Documentation: 这是Android文档的示例:

<?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. 我们可以使用XAML或C#中的某些功能在Windows(电话)应用程序上获得相同的效果。 (Or Universal Apps for that matter). (或与此相关的通用应用)。

Nowadays I use the Listeners GotFocus, LostFocus, etc. But i don't think it is a straghtforward solution. 如今,我使用了GotFocus,LostFocus等侦听器。但是,我认为这不是一种直截了当的解决方案。

Anyone has a better idea on how to do this? 任何人都有一个更好的主意如何做到这一点?

You can define a complete multi-state layout of a control purely in xaml. 您可以仅在xaml中定义控件的完整多状态布局。 Define a custom style for button and set the Template property. 为按钮定义自定义样式并设置Template属性。 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. 在那里,您可以为PressedMouseOver等设置不同的VisualStates

To get the button default style use Blend as described here: http://www.geekchamp.com/tips/windows-phone-button-default-style 要获取按钮默认样式,请按照此处所述使用Blend: 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 有关自定义按钮模板的更多信息: http : //www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-button

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM