我有一个comboBox,其样式设置为具有文本行和复选框,以允许用户检查不同事物的列表。我试图做的是禁用组合框中的一行选择。
我的查看代码:
//func2
functon getPromise(options) {
return apiRequest(options).then(response => {
if (response.body.hasOwnProperty('message')) {
console.error(`Error: Invalid token`);
const payload = {
url: 'https://abc',
form:{},
method: 'post'
};
return apiRequest(payload).then(result => {
options.headers.Authorization = 'Bearer '+result.body;
return getPromise(options); // seems Issue having this line to call again
});
} else {
return response.body;
}
});
}
这是我的下拉菜单的照片:
以下是我不想要的照片:
我想禁用用户选择特定行的功能,但保留他们在下拉列表中选择各种复选框的功能。有样式的方法吗?
答案 0 :(得分:1)
我遇到了同样的问题,我通过结合使用ToggleButton
和Popup
(而不是使用ComboBox
)来解决了这个问题
注意:未测试
<ToggleButton x:Name="filterButton" />
<Popup x:Name="popup"
AllowsTransparency="True"
StaysOpen="False"
PlacementTarget="{Binding ElementName=filterButton}"
IsOpen="{Binding ElementName=filterButton,Path=IsChecked,Mode=TwoWay}">
<ItemsControl ItemsSource="{Binding HeaderList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsChecked}"/>
<TextBlock Text="{Binding HeaderName}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Popup>
答案 1 :(得分:0)
您可以尝试在selectionchangedchanged事件中将组合框的selectedindex设置为-1
//
// UITextFiled+fixspace.swift
// anbaobao
//
// Created by 荆文征 on 2018/11/9.
// Copyright © 2018 com.baimaodai. All rights reserved.
//
import UIKit
extension UITextField {
/// Runtime 键
private struct AssociatedKeys {
static var toggleState: UInt8 = 0
}
/// 是否已经修复 右侧问题
private var isFixedRightSpace: Bool {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.toggleState) as? Bool ?? false
}
set(newValue) {
objc_setAssociatedObject(self, &AssociatedKeys.toggleState, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.textAlignment == .right && !isFixedRightSpace {
self.isFixedRightSpace = true
self.addTarget(self, action: #selector(replaceNormalSpacesWithNonBreakingSpaces(textFiled:)), for: UIControl.Event.editingChanged)
}
return super.hitTest(point, with: event)
}
@objc func replaceNormalSpacesWithNonBreakingSpaces(textFiled: UITextField) {
if textFiled.markedTextRange == nil && textFiled.text?.contains(find: " ") ?? false {
let editRange = selectedTextRange
textFiled.text = textFiled.text?.replacingOccurrences(of: " ", with: "\u{00a0}")
selectedTextRange = editRange
}
}
}