我想單擊它後禁用我的按鈕。我想看到它,但我不想點擊後再次點擊。 Windows Phone 8我該怎麼做?單擊後禁用按鈕
button1.isEnabled = false; //hide button.
我不想隱藏它,然後再次單擊它。
我想單擊它後禁用我的按鈕。我想看到它,但我不想點擊後再次點擊。 Windows Phone 8我該怎麼做?單擊後禁用按鈕
button1.isEnabled = false; //hide button.
我不想隱藏它,然後再次單擊它。
UIElement.IsHitTestVisible Property
獲取或設置聲明此元素是否可能 被作爲命中測試
您可以在函數的開始設置your_btn.IsHitTestVisible = False
,然後將其重置爲True
返回的值在端
或
UIElement.IsEnabled Property
獲取或設置一個值,指示在 用戶界面此元素是否啓用(UI)
使用的IsEnabled(即背景設置爲透明的),您可以創建一個樣式資源(去在XAML中,right click on the view of your_btn->edit template->edit a copy...
,然後修改VisualState x:Name="Disabled"
字段設置Storyboard.TargetProperty="Background" Value="your_background"
。通過這種方式,你還可以模擬保持按鈕... 資源風格是
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
<Setter Property="Padding" Value="10,5,10,6"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneButtonBasePressedForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneAccentBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
而且你的按鈕將有Style="{StaticResource ButtonStyle1}"
財產
你有沒有試過把點擊事件這樣一行?
myButton.IsHitTestVisible = false;
試試這個 -
private void button1_Click(object sender, RoutedEventArgs e)
{
button1.Click -= button1_Click;
//Then do what the button does.
}
所以,第一次點擊之後,事件處理程序將從Click事件退訂。所以,沒有更多的點擊會調用事件處理程序。