在哪里可以找到列出控件中所有状态的属性? [英] Where can I find the property that list all the states in a control?

查看:96
本文介绍了在哪里可以找到列出控件中所有状态的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看winrt项目的模板,它的后退按钮具有以下样式:

I was looking at the template for a winrt project and it has the following style for the back button:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
        <VisualState x:Name="Normal" />
        <VisualState x:Name="PointerOver">
            ...
        </VisualState>
        <VisualState x:Name="Pressed">
           ...
        </VisualState>
        <VisualState x:Name="Disabled">
            ...
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup x:Name="FocusStates">
        <VisualState x:Name="Focused">
            ...
        </VisualState>
        <VisualState x:Name="Unfocused" />
        <VisualState x:Name="PointerFocused" />
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

我假设上面的VisualStates是按钮状态,但是我不知道它在哪里跟踪按钮对象以及框架如何将状态绑定到视觉状态。

I am assuming the above VisualStates are button States, but I can't figure out where this is being tracked on the button object and how the framework binds the state to the visual state.

我一直在互联网上寻找更好的理解,但无济于事。请帮助我了解这是如何捆绑在一起的。我知道您可以从后面的代码手动进入特定状态,但是这里似乎缺少约定。

I have been looking all around the internet to get a better understanding, but to no avail. Please help me understand how this is all tied up together. I know you can manually go to a specific state from code behind, but there seems to be a convention here that I am missing.

推荐答案

没有没有属性列出控件状态。

There is no property that lists a controls states.

根据MSDN控件,作者必须提供控件合约,以便ControlTemplate作者知道要在模板中放入什么。

According to MSDN Control Authors must provide a control contract so that ControlTemplate authors will know what to put in the template.

控制合同具有三个要素:

A control contract has three elements:


  • 控件的视觉要素逻辑使用。

  • 控件的状态以及每个状态所属的组。

  • 在视觉上影响控件的公共属性。

视觉元素和状态均以 Class Attributes

[TemplatePart(Name = "XXX", Type = typeof(RepeatButton))]
[TemplatePart(Name = "YYY", Type = typeof(RepeatButton))]
[TemplateVisualState(Name = "Focused", GroupName = "FocusedStates")]
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusedStates")]

您应该查看默认的控件样式和模板我认为您要查找的所有数据都在那里。

you should go over the default Control Styles and Templates I think all the dat you are looking for will be there.

如果您必须在运行时获取数据,然后n使用 Reflection 获取给定的类属性,例如:

if you have to get the data in run time then you can use Reflection to get a given class Attributes like that :

System.Reflection.MemberInfo info = typeof(MyClass);
object[] attributes = info.GetCustomAttributes(true);

for (int i = 0; i < attributes.Length; i++)
{
  if (attributes[i] is TemplatePart || attributes[i] is TemplateVisualState)
  {
     System.Console.WriteLine(((TemplateVisualState) attributes[i]).Name);
  }   
}

阅读 MSDN文章它将使事情变得更清楚

read this MSDN Article it will make things clearer

这篇关于在哪里可以找到列出控件中所有状态的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆