我有一個帶有按鈕的登錄表單(btnLogin)。當用戶點擊btnLogin,以下Storyboard
被觸發禁用btnLogin,txtUsername,pbPassword ...反向觸發動畫如果方法失敗使用Xaml,而不是代碼
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" />
</BooleanAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="txtUsername" Storyboard.TargetProperty="IsEnabled" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" />
</BooleanAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="pbPassword" Storyboard.TargetProperty="IsEnabled" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
...因爲這Storyboard
運行時,Button.Click
事件也連接到btnLogin_Click
方法驗證用戶憑證。很公平!
目前,如果登錄嘗試失敗,我必須使用以下(髒?!)代碼btnLogin_Click
重新啓用btnLogin,txtUsername,pbPassword控制等等細節可以重新進入......
btnLogin.Triggers.Clear();
btnLogin.BeginAnimation(UIElement.IsEnabledProperty, null);
txtUsername.BeginAnimation(UIElement.IsEnabledProperty, null);
pbPassword.BeginAnimation(UIElement.IsEnabledProperty, null);
我可以使用Xaml來處理這個重新啓用嗎?我確信我可以,我只是不知道該怎麼做?!
感謝您的幫助:O)
UPDATE
我使用EnterActions
和ExitActions
試圖通過bars222的建議,但這種做法有沒有辦法確定btnLogin_Click
事件導致登錄成功或失敗。
此外,我認爲最好使用數據綁定爲你的情況,但它需要一些代碼背後。 – bars222
感謝您的回覆。不幸的是,該方法根本不禁用按鈕。我認爲它可能會禁用,然後立即啓用它。你能給我提供關於你提到的數據綁定解決方案的更多信息嗎? –
對於第一個答案,我建議授權表單將在成功驗證過程後被禁用。用數據綁定示例更新答案。 – bars222