2012-12-16 26 views
0

我正在開發Windows 8中的xaml/c#metro樣式應用程序。我想模擬Microsoft日曆應用程序組合框樣式(在事件詳細信息頁面)。我的意思是,選擇後有彩色框和邊框的行爲。我如何使用視覺狀態來做到這一點?組合框樣式窗口地鐵應用程序

+0

退房HTTP:// WWW。 devcomponents.com/dotnetbar/ – sircapsalot

回答

1

有這個沒有標準的控制,你必須創建自己的/擴展標準組合框

+0

我知道沒有標準的控制。我的問題是關於實現這一效果。我可以通過在c#中使用GotFocus和LostFocus事件來實現類似的功能,但我想使用VisualState修改組合框模板。我該怎麼做?謝謝 –

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