0

我正在 Windows 8 中开发 xaml/c# Metro 风格应用程序。我想模拟 Microsoft 日历应用程序组合框风格(在事件详细信息页面中)。我的意思是,在选择后具有彩色框和边框的行为。如何使用视觉状态来做到这一点?

4

2 回答 2

1

There is no standard control for this, you have to create your own / extend the standard combobox

于 2012-12-17T22:20:28.450 回答
0

像这样的东西应该工作:

<Combobox.Template>
    <ControlTemplate>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Unfocused"/> <!--leave the unfocused state empty if the control already looks "unfocused" -->
                <VisualState x:Name="Focused">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="background" Storyboard.TargetProperty="Opacity" To="0.2" Duration="0"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Border x:Name="background" Background="Red" Opacity="0" />
        <!--other stuff-->
    </ControlTemplate>
</Combobox.Template>

Combobox 控件根据鼠标/键盘输入(如聚焦、按下、鼠标悬停等)自动切换其内置状态。通过切换状态,为当前状态定义的情节提要将反转,您为将应用新的状态。您可以在此处查看可用状态:http: //msdn.microsoft.com/en-us/library/ms752094.aspx

(使用代码隐藏,您还可以根据事件等实现自己的状态,但这应该很少需要。)

于 2013-06-24T09:53:44.013 回答