我在WP應用程序中創建了一個自定義按鈕。我想讓它看起來像一個標準的Windows Phone 8按鈕。 XAML代碼創建自定義Windows Phone按鈕
<Grid Name="btnCancle" Height="76" Width="76" Margin="24" ManipulationStarted="btnCancle_ManipulationStarted" ManipulationCompleted="btnCancle_ManipulationCompleted" >
<Ellipse Name="ellipseCancle" Grid.Row="2" Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="3" Height="76" Width="76" />
<Canvas x:Name="appbar_close" Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="31.6666" Height="31.6667" Canvas.Left="22.1666" Canvas.Top="22.1667" Stretch="Fill" Fill="{StaticResource PhoneForegroundBrush}" Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "/>
</Canvas>
</Grid>
的事件處理程序的
private void btnCancle_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
Brush br = (Brush)Application.Current.Resources["PhoneAccentBrush"];
ellipseCancle.Fill = br;
}
private void btnCancle_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
Brush br = (Brush)Application.Current.Resources["PhoneBackgroundBrush"];
ellipseCancle.Fill = br;
}
我的問題是,當我按一下按鈕,有按鈕充當notmal按鈕之前稍有延遲。(該backgrounc變化碼到PhoneAccentColor並返回)。只要我觸摸它,背景顏色不會改變。但經過一次或兩次嘗試後,其行爲正常。我正在編寫代碼以在Tap事件處理程序中執行該按鈕的操作。但只要用戶觸摸它,我就需要使它像正常按鈕一樣運行。我做錯了什麼,我能做些什麼來解決它?請幫助..在此先感謝..
按鈕的視覺外觀是巨大的。有用。但是,只要我在模擬器中運行應用程序,我得到一個UnhandledException。這可能是什麼原因? –
@KasunKV原因是因爲視覺狀態會嘗試根據按鈕模板的名稱來設置按鈕,請參閱我的更新,它將以與正常按鈕按下時的行爲相同的方式爲您的自定義按鈕着色。 – Mark