Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ComboBox]OnCurrentIndexChanged:连续触发三次 #821

Open
speauty opened this issue Mar 26, 2023 · 0 comments
Open

[ComboBox]OnCurrentIndexChanged:连续触发三次 #821

speauty opened this issue Mar 26, 2023 · 0 comments

Comments

@speauty
Copy link

speauty commented Mar 26, 2023

最近遇到个小问题,在使用ComboBox组件,由于需要获取当前选中项,然后就注册了OnCurrentIndexChanged函数。不过实际情况和预期有点小差别,那个函数被连续触发了三次,是因为某些属性未正确设置的原因么?相关源码如下:

package main

import (
	"fmt"
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
	"time"
)

func main() {
	var win *walk.MainWindow
	MainWindow{
		AssignTo: &win,
		Title:    "ComboBox",
		MinSize:  Size{600, 400},
		Layout:   VBox{},
		Children: []Widget{
			ComboBox{
				Model: []string{"Combo", "Box", "CB"},
				OnCurrentIndexChanged: func() {
					fmt.Println(time.Now().String())
					// 2023-03-26 15:10:09.3184992 +0800 CST m=+2.503204401
					// 2023-03-26 15:10:09.3393394 +0800 CST m=+2.524044601
					// 2023-03-26 15:10:09.340897 +0800 CST m=+2.525602201
				},
			},
		},
	}.Run()
}

其中walk库的相关信息 github.com/lxn/walk v0.0.0-20210112085537-c389da54e794

@speauty speauty changed the title [OnCurrentIndexChanged]ComboBox:连续触发三次 [ComboBox]OnCurrentIndexChanged:连续触发三次 Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant