- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
A 有一个 ListBox,需要在特定情况下聚焦特定项目(例如,显示搜索结果时)。这是通过附加属性使用以下函数完成的:
public static void OnElementIndexPropertyChanged (DependencyObject DObject, DependencyPropertyChangedEventArgs Args)
{
ListBox ListBoxControl = DObject as ListBox;
if (ListBoxControl != null &&
(int)Args.NewValue != -1)
{
ListBoxControl.ScrollIntoView (ListBoxControl.Items[(int)Args.NewValue]);
ListBoxControl.UpdateLayout ();
var ListBoxItem = (ListBoxItem)ListBoxControl.ItemContainerGenerator.ContainerFromItem (ListBoxControl.Items[(int)Args.NewValue]);
ListBoxControl.SelectedItem = ListBoxItem;
ListBoxItem.Focus ();
}
}
现在,ListBoxControl 确实获得了键盘焦点(如果我按住 Alt,它将在其周围显示一个虚线边框,并且它使用箭头键向上/向下移动它可以正常工作),但是,样式没有更新。最后选择的项目留下蓝色突出显示,而新选择的项目不会更新以显示蓝色突出显示。它只能在第一次正确工作,在项目被聚焦和突出显示之前。
除了手动更改背景/样式之外,还有其他解决方法吗?
最佳答案
我习惯于将 SelectedItem
设置为实际项目而不是该项目的容器。使用 SelectedIndex
似乎也更自然,因为您已经有了索引。通过将 SelectedItem
行替换为以下内容,我能够获得使用该样式的 ListBox
的选择:
ListBoxControl.SelectedIndex = (int)Args.NewValue;
附言
我应该补充一点,也许我没有完全理解这个问题,因为我想知道为什么你不只是使用 SelectedIndex
而不是自定义附加属性来更改选择(可能是因为滚动会不一样吗?)。
关于c# - 聚焦 ListBoxItem 不会更新其样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37325824/
您好,我找不到任何类似的问题,所以我发布了新问题。在下面的代码中,我使用 ListBoxItems 创建 ListBox 控件,每个 ListBoxItems 都包含内部单选按钮。当我单击单选按钮时,
我将以下数据模板应用于列表框: 当我单击按钮时,命令被触发,但 ListBoxItem 没有被选中。如何强制它被选中,以便我可以在我的“执行
我想在数据绑定(bind)的多个列表框上实现拖放 - 使用 MVVM 模式。我不是试图在列表框之间拖放,而是希望用户能够在每个列表框中拖放列表框项,以便他们可以重新排列排序顺序。我在 SO 上发现这篇
我想实现一种效果,其中 ListBoxItem 被选中(突出显示)几秒钟,然后被取消选中。尝试使用淡入淡出效果实现简单的控件突出显示,但为了使事情正常进行,我需要相应地更改一个属性。 我有一个 IsS
我尝试实现一个 ListBox,其中所选项目比其他项目更详细地显示。 Josh Smith 在 his blog 上展示了一种方法. 为了增强用户体验,我想对变化进行动画处理(即项目变大,附加信息淡入
我只能找到如何通过单击组件 -> Items Editor 来创建 ListBoxItem。 我们如何使用 Firemonkey 以编程方式创建 ListBoxItem? 最佳答案 只需创建列表框项,
是否可以从 Windows Presentation Foundation 的代码隐藏更改选定的 ListBoxItem? 这真的是一个非常简单的任务,我有一个 Next 和 Previous 按钮,
我有一个带样式的列表框,包括带样式的 Listboxitem。我正在尝试创建一个将不透明度从 0 更改为 1 的动画,以使项目显示在列表中。我已设法使用以下代码做到这一点:
我们如何在运行时向 Windows Metro 风格应用程序中的 ListBox 控件添加新项目? 我来自 WinForms,所以你可以想象,我现在很困惑。 我有以下内容: public class
由于某些原因,我必须在后面的代码中初始化 ListBox 项,原因太复杂了。 在 WPF UserControl 显示期间调用 LoadFamily()。 public void LoadFamily
我正在为一个学校项目构建一个聊天室。在聊天室中有一个包含所有消息的列表框。 Messages 是一个包含所有消息的 ObservableCollection。 Message 类有发件人姓名变量。
我想将用户控件 (View) 绑定(bind)到 ListBoxItem。 ListBox 绑定(bind)到 ViewModel 的集合。我已将 ListBox 的 ItemTemplate 设置为
我在设置 HighlightBrushKey 时遇到问题的 SelectedItem的 Listbox在 WPF 中。我的意图是根据代码中给定的 bool 值设置 Item 的颜色。 我试过以下步骤:
实际的视觉效果由 DataTemplate 决定。在运行时,如何遍历 ListBoxItem 的所有可视元素? 最佳答案 假设您引用了 ListBoxItem 之一列表中的 s,您可以使用 Visua
这是我的问题:
我有一个 ListBox 控件;我如何使用下面的代码为每个 ListBoxItem 设置 ToolTip。
我想做这样的事情。
我正在尝试为我的 wpf 应用程序中的业务对象定义一个 dataTemplate,该对象的集合绑定(bind)到 ListBox。
我有一个 ListBox 控件;我如何使用下面的代码为每个 ListBoxItem 设置 ToolTip。
我正在创建一个自定义混合行为来作用于 ListboxItem,即 public class DragtestBehaviour : Behavior { public DragtestBeha
我是一名优秀的程序员,十分优秀!