我想在点击后禁用我的按钮。我想看到它,但我不想在点击后再次点击。在 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}"
属性
您是否尝试过在 Click Event 中添加这样一行?
myButton.IsHitTestVisible = false;
尝试这个 -
private void button1_Click(object sender, RoutedEventArgs e)
{
button1.Click -= button1_Click;
//Then do what the button does.
}
因此,在第一次单击之后,事件处理程序将取消订阅 Click Event。因此,没有进一步的点击将调用事件处理程序。