标签: togglebutton

为什么WPF切换按钮脉冲一旦未选中

在桌面应用程序中,我有一个切换按钮:

<ToggleButton x:Name="CFStglBtn" Checked="cfsCBox_Checked"
              Unchecked="cfsCBox_Unchecked"
              IsChecked="True" HorizontalAlignment="Left" Margin="5,0,0,0">
    <StackPanel Orientation="Horizontal">
        <Image Source="assets\telephone.png" Margin="3,0,0,0" />
        <TextBlock Text="CFS" FontSize="10" Margin="5,5,5,0"
                   Foreground="DarkSlateGray"/>
    </StackPanel>
</ToggleButton>
Run Code Online (Sandbox Code Playgroud)

对于Checked事件,我设置一个值,然后执行方法FilterView(); //省略代码

未经检查的状态正好相反.重置变量并再次执行该方法

我的问题是我注意到,当我取消选中切换按钮时,按钮继续脉冲或闪烁(从蓝色变为铬色),就好像它仍然具有焦点一样.按钮将保持这样,直到单击另一个按钮.

有没有办法去除这个焦点,以便当取消选中该按钮时,按钮返回到未检查状态,没有闪烁/脉冲颜色.

  • 从上面可以看出,这是一个标准的切换按钮,没有样式或自定义
  • 我只用一个常规按钮测试了这个,我发现点击时按钮会继续脉冲/闪烁,直到点击另一个按钮.

你如何解决这个问题或防止这种影响发生.

谢谢

wpf wpf-controls togglebutton

5
推荐指数
2
解决办法
4497
查看次数

为什么IsChecked不会更改此切换按钮?

我有以下用于切换按钮的xaml:

<ToggleButton Margin="0,3" Grid.Row="3" Grid.ColumnSpan="2" Command="{Binding DataContext.SelectAllCommand, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
  <ToggleButton.Style>
   <Style TargetType="{x:Type ToggleButton}">
       <Setter Property="Content" Value="Select All"/>
       <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Content" Value="Select None"/>
                <Setter Property="Command" Value="{Binding DataContext.SelectNoneCommand, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
            </Trigger>
          </Style.Triggers>
      </Style>
  </ToggleButton.Style>
</ToggleButton>
Run Code Online (Sandbox Code Playgroud)

但是IsChecked单击按钮时,属性永远不会更新.

如果我使用snoop并强制IsChecked为True,那么触发器就会启动.

wpf togglebutton ischecked

5
推荐指数
1
解决办法
4715
查看次数

抑制 Gtk.ToggleButton.set_active 上的信号

有没有办法抑制当您使用 set_active() 设置 ToggleButton 的状态时发出的“切换”信号?

我想用 GtkToggleButton 表示连接状态。由于状态可以从其他事件中更改,而不仅仅是单击按钮,我想更新状态更改信号上的按钮,但我希​​望不发出信号(当它发生时,我不需要运行断开连接过程)已经断开)。我可以只检查连接状态,但在信号时间前后似乎不一致。

也欢迎除 ToggleButtons 之外的其他解决方案。

谢谢

gtk state signals pygtk togglebutton

5
推荐指数
1
解决办法
1153
查看次数

选中时更改切换按钮的背景颜色

我正在尝试区分单击时切换按钮的状态。我有下面的片段

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="OnOffToggleImageStyle" TargetType="ToggleButton">
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="DimGray"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <ToggleButton Height="60" Content="Text" Style="{StaticResource OnOffToggleImageStyle}">
        </ToggleButton>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

但是,当样式中的 IsChecked 值设置为“True”时,这不起作用。当设置为 false 时它起作用。

我想知道为什么。任何答案!

c# wpf styles togglebutton

5
推荐指数
1
解决办法
7382
查看次数

触发MouseOver状态后,为什么ColorAnimation for Checked状态不会保持颜色?

我遇到的问题与ControlTemplateToggleButton我创造.

当按钮为时Checked,ColorAnimation触发a并且控件的背景改变颜色.但是,如果用户进入MouseOver状态,则会触发另一个影响按钮背景的动画.

当鼠标不再处于该MouseOver状态时,控件不会返回到处于该Checked状态时应该处于的颜色.我不确定为什么在MouseOver触发状态时这种情况不会持续存在.

VisualStateManager我的部分ControlTemplate看起来有点儿像这样:

<VisualStateManger.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
        <VisualState x:Name="Normal"></VisualState>
        <VisualState x:Name="MouseOver">
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BackgroundBorder"
                    Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                    To="Gold" Duration="0:0:0.3" />
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup x:Name="CheckedStates">
        <VisualState x:Name="Checked">
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BackgroundBorder"
                    Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                    To="PaleGoldenrod" Duration="0:0:0.3" />
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Run Code Online (Sandbox Code Playgroud)

wpf controltemplate togglebutton visualstates

5
推荐指数
1
解决办法
726
查看次数

如何在android中保存(切换)按钮状态?

我在我的andorid应用程序中使用SWITCH(如android切换按钮)而不是普通按钮.启用和禁用交换机时,代码工作正常.但我想存储开关的状态.假设我启用了交换机并关闭了我的应用程序,后台代码将正常运行但开关状态将更改为禁用.

每次关闭应用程序时,开关状态都将被禁用.有没有办法存储开关状态?

android switch-statement togglebutton

5
推荐指数
1
解决办法
1万
查看次数

使用操作按钮启用和禁用侧边栏切换按钮

我正在寻找一个代码片段,使用它,我可以在 Shinydashboard 标题中启用/禁用侧边栏切换按钮。

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- shinyUI(dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs()
  )
))

server <- shinyServer(function(input, output, session) {
  addClass(selector = "body", class = "sidebar-collapse") # Hide Side Bar
})

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

让我知道是否有人可以提供帮助???

togglebutton shiny shinydashboard shinyjs

5
推荐指数
2
解决办法
1897
查看次数

使用 Qt 实现切换按钮的最佳方法

使用 Qt 框架实现切换按钮的最佳方法是什么?

编辑:

我知道的唯一可能性是QPushButton. 根据 Qt 文档,QPushButton::setCheckable(bool)允许有开/关行为。如何让它出现如下所示?知道我使用 Qt 5.1.1

在此输入图像描述

user-interface qt togglebutton

5
推荐指数
1
解决办法
2万
查看次数

如何在wxpython中设置切换按钮的颜色?

我有一个已创建的按钮集合,需要在按下按钮时更改按钮的颜色。当前,它设置默认颜色(灰色=无效;浅蓝色=有效):

在此处输入图片说明

但我想将活动颜色更改为红色。

这是我的按钮类:

class ButtonClass(wx.Panel):
    def __init__(self, parent, name, id):
        wx.Panel.__init__(self, parent)
        self.name = name
        self.taskid = id

        self.button = wx.ToggleButton(self, 1, size=(50, 50))
        self.button.SetLabel('Start')

        self.mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.mainSizer.Add(self.button)

        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggledbutton, self.button)

    # Where the buttons change state
    def toggledbutton(self, event):

        # Active State
        if self.button.GetValue() == True:

            self.button.SetLabel('Stop')

        # Inactive State
        if self.button.GetValue() == False:

            self.button.SetLabel('Start')
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用self.button.SetColourself.button.SetBackgroundColourself.button.SetForegroundColour所有这一切都没有成功。有没有办法在wxpython中完成此操作?

wxpython colors button togglebutton

4
推荐指数
1
解决办法
9026
查看次数

切换按钮事件无法在各种设备上运行

我正在各种型号上测试我的应用程序,我已经意识到切换按钮ON和OFF事件不起作用.这是设备列表:

三星YS5360三星Galaxy Note三星S Plus HTC Sensation XE HTC Wildfire S摩托罗拉RAZR
LG Optimus Black索尼爱立信Xperia neo V

因为我遵循了所有Android规范,所以我不确定我做错了什么.这些事件适用于其他设备.我可以请一些帮助吗?

[重新编辑]

这就是我实现监听器的方式:

    @Override
    public void onCheckedChanged(CompoundButton arg0, boolean change) {

        if(change){
            if(text.containsKey("on")){
                // do something
            }
        }else{
            if(text.containsKey("off")){
                // do something
            }
        }
        if(text.containsKey("clicked")){
            // do something
        }
     // }
   }
};
Run Code Online (Sandbox Code Playgroud)

我检查ON和OFF状态,但这似乎不适用于其他设备.

events android togglebutton android-event

4
推荐指数
1
解决办法
1840
查看次数