Flyout中ComboBox失效
参见这篇文章:https://blogs.msdn.microsoft.com/wsdevsol/2016/09/14/combobox-from-an-appbarbutton-loses-mouse-input-on-1607/
Several developers have asked why a ComboBox on a Flyout attached to an AppBarButton ignores mouse clicks after upgrading their UWP apps to target build 14393 (Windows 10, version 1607 – also known as the Windows 10 Anniversary Update). The same Xaml worked fine unchanged when the app targeted build 10586 (Windows 10, version 1511).
<tl;dr>
Apps can reenable focus here by setting the AppBarButton’s AllowFocusOnInteraction property to true.
The new behavior is a side effect of the new focus system which allows users to interact with controls such as AppBarButtons without stealing the focus from the control they’re trying to modify. This has been a huge request from devs whose apps have scenarios such as text editors: the app can have formatting buttons (e.g. bold, italic, colors) which change the formatting without affecting the text’s focus or selection.
The new behavior enhances the common AppBarButton use case so AppBarButtons default to AllowFocusOnInteraction to false if the app opts in to new behavior by targeting build 14393.
In the case where the AppBarButton brings up a ComboBox, the ComboBox depends on being able to get the focus. For this case the app needs to override the default and explicitly set AllowFocusOnInteraction to true.
How do I let the ComboBox get focus?
If you just fired up your app in Visual Studio and added AllowFocusOnInteraction to the AppBarButton Xaml you probably discovered that the editor rejected it. AllowFocusOnInteraction is only available in build 14393 and later. If the app’s minimum version is lower than that then it can’t be used in version flexible Xaml.
Set in code behind with adaptive code
The standard pattern to set properties that may or may not exist is to check if it’s present with the Windows.Foundation.Metadata.ApiInformation class:
private void AppBarButton_Loaded(object sender, RoutedEventArgs e)
{
bool allowFocusOnInteractionAvailable =
Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent(
"Windows.UI.Xaml.FrameworkElement",
"AllowFocusOnInteraction"); if (allowFocusOnInteractionAvailable)
{
var s = sender as FrameworkElement;
if (s != null)
{
s.AllowFocusOnInteraction = true;
}
}
}
Set in Xaml via an Attached Property
public class CompatExtensions
{
public static bool GetAllowFocusOnInteraction(DependencyObject obj)
{
return (bool)obj.GetValue(AllowFocusOnInteractionProperty);
}
public static void SetAllowFocusOnInteraction(DependencyObject obj, bool value)
{
obj.SetValue(AllowFocusOnInteractionProperty, value);
}
// Using a DependencyProperty as the backing store for AllowFocusOnInteraction.
// This enables animation, styling, binding, etc...
public static readonly DependencyProperty AllowFocusOnInteractionProperty =
DependencyProperty.RegisterAttached("AllowFocusOnInteraction",
typeof(bool),
typeof(CompatExtensions),
new PropertyMetadata(0, AllowFocusOnInteractionChanged)); private static bool allowFocusOnInteractionAvailable =
Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent(
"Windows.UI.Xaml.FrameworkElement",
"AllowFocusOnInteraction");
private static void AllowFocusOnInteractionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (allowFocusOnInteractionAvailable)
{
var element = d as FrameworkElement;
if (element != null)
{
element.AllowFocusOnInteraction = (bool)e.NewValue;
}
}
}
}
And then set the property in Xaml without worrying about the app version:
<AppBarButton local:CompatExtensions.AllowFocusOnInteraction="True" Icon="Setting">
<AppBarButton.Flyout>
<Flyout>
<StackPanel Orientation="Vertical" >
<ComboBox>
<ComboBoxItem Content="Red" IsSelected="True" />
<ComboBoxItem Content="Green" />
<ComboBoxItem Content="Blue"/>
</ComboBox>
</StackPanel>
</Flyout>
</AppBarButton.Flyout>
</AppBarButton>
Flyout中ComboBox失效的更多相关文章
- winform中ComboBox实现text和value,使显示和值分开,重写text和value属性
winform的ComboBox中只能赋值text,显示和值是一样的,很多时候不能满足根本需要,熟悉B/S开发的coder最常用的就是text和value分开的,而且web下DropDownList本 ...
- 第三方支付过程中session失效问题
第三方支付过程中session失效问题 时间 2015-05-13 12:36:23 IT社区推荐资讯 原文 http://itindex.net/detail/53436-session-问题 ...
- Sublime Text 2/3中Autoprefixer失效解决方法
###Sublime Text 2/3中Autoprefixer失效解决方法: 相信每个前端er都会使用Subl这款工具吧,因为它有上千款开源的插件,而且功能各异,这里给大家带来的是标题中Autopr ...
- C# WinForm 中ComboBox数据绑定的问题 (转)
来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...
- EasyUI 中 Combobox里的onChange和onSelect事件的区别
EasyUI 中 Combobox 选项发生改变时会触发 onChange,onSelect,onClick 3 个事件. 最近要做一个级联的 Combo 菜单,类似于选择地址时让用户填写省,市,区的 ...
- [C#]WinForm 中 comboBox控件之数据绑定
[C#]WinForm 中 comboBox控件之数据绑定 一.IList 现在我们直接创建一个List集合,然后绑定 IList<string> list = new List<s ...
- jquery easyUI中combobox的使用总结
jquery easyUI中combobox的使用总结 一.如何让jquery-easyui的combobox像select那样不可编辑?为combobox添加editable属性 设置为false ...
- silverlight中 ComboBox绑定数据库,并获取当前选定值
silverlight中 ComboBox绑定数据库,并获取当前选定值 在silverlight中 用combobox下拉菜单绑定数据库的方法和用DataGrid绑定数据库的方法类似. page.xa ...
- 解决QML开发中ComboBox中一个已选择项没有清除的问题
解决QML开发中ComboBox中一个已选择项没有清除的问题 近期使用QML开发一个项目.须要使用ComboBox进行显示.当进行一个操作时,须要向ComboBox加入一个元素,当进行另外一个操作时. ...
随机推荐
- 如何注册微信小程序
小程序是一种新的开放能力,可以在微信内被便捷地获取和传播,同时具有出色的使用体验.开发者可以根据平台提供的能力,快速地开发一个小程序. 开放内容包括: 开放注册范围:企业.政府.媒体.其他组织: 开发 ...
- Android之RecyclerView的原生Bug-Inconsistency detected. Invalid view holder adapter positionViewHolder{a1bbfa3 position=2 id=-1, oldPos=-1, pLpos:-1 no parent}
今天在运行自己编写的App时,突然发现App在运行时闪退,然后就查看了Android Studio的Log,发现了这个错误,上网查了一下,才知道是RecyclerView的原生Bug,在数据更新时会出 ...
- 转载文章(Redis中对key的操作)
转载地址:http://www.cnblogs.com/stephen-liu74/archive/2012/03/26/2356951.html 一.概述: 在该系列的前几篇博客中,主要讲述的是与R ...
- get和post的区别
http://localhost:8080/shopc/check.do?username=zhangsan&pwd=123456 http://localhost:8080/shopc/ch ...
- 步步深入:MySQL架构总览->查询执行流程->SQL解析顺序
前言: 一直是想知道一条SQL语句是怎么被执行的,它执行的顺序是怎样的,然后查看总结各方资料,就有了下面这一篇博文了. 本文将从MySQL总体架构--->查询执行流程--->语句执行顺序来 ...
- Couchbase 环境搭建与使用(C#)
Couchbase Couchbase Server (前身是 Membase) 是一个分布式的面向文档的 NoSQL 数据库管理系统,该系统联合了 CouchDB 的简单和可靠以及 Memcache ...
- Keepalived+LVS+nginx双机热备
Keepalived简介 什么是Keepalived呢,keepalived观其名可知,保持存活,在网络里面就是保持在线了, 也就是所谓的高可用或热备,用来防止单点故障的发生. Keepalived采 ...
- WPF 自定义CheckBox样式
自定义CheckBox样式,mark一下,方便以后参考复用 设计介绍: 1.一般CheckBox模板太难看了,肯定要重写其中的模板 2.模板状态为未选中状态和选中状态,设置为默认未选中就好了. 默认状 ...
- Servlet入门笔记
一.一个简单的Servlet 在servlet 3.0之前,下面是基本步骤: 1.新建一个class名为FirstServlet,让它继承javax.servlet.http.HttpServlet: ...
- css实现页面元素居中
水平居中 对于已知宽度的块级元素实现水平居中只需要设置 margin-left:auto; margin-right:auto; 对于多个块级元素实现水平居中只需要设置 //1 父类{ text-al ...