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加入一个元素,当进行另外一个操作时. ...
随机推荐
- window环境下将solr6.3部署到tomcat中
1.我下载的solr是6.3版本的,需要jdk1.8及以上,tomcat8 JDK1.8的下载地址:http://www.Oracle.com/technetwork/Java/javase/down ...
- DbMigration使用方法
1.Enable-Migrations -ContextTypeNameLITCS.Data.gmisContext Enable-Migrations 命令创建了一个新的Migrations文件夹 ...
- 经典的一款jQuery soChange幻灯片
soChange一款多很经典的幻灯片的jQuery插件. 实例预览 引入文件 <link rel="stylesheet" type="text/css" ...
- 前端之HTML知识点整理
一.html概述 htyper text markup language 即超文本标记语言 超文本: 就是指页面内可以包含图片.链接,甚至音乐.程序等非文字元素. 标记语言: 标记(标签)构成的语言 ...
- 学习笔记 HTTP参数污染注入
HTTP参数污染注入源于网站对于提交的相同的参数的不同处理方式导致. 例如: www.XX.com/a?key=ab&key=3 如果服务端返回输入key的值,可能会有 一: ab 二:3 三 ...
- iOS之UI组件整理
作者:神兽gcc 授权本站转载. 最近把iOS里的UI组件重新整理了一遍,简单来看一下常用的组件以及它们的实现.其实现在这些组件都可以通过Storyboard很快的生成,只是要向这些组件能够变得生动起 ...
- 关于addSubView需要注意的事项 -今天吃了一个大亏
addSubview: Adds a view to the end of the receiver’s list of subviews. 译:增加一个视图到接收者的子视图列表中. - (void) ...
- LAMP坏境和LNMP环境安装Nagios4.1.1和基本配置
----------------------------------------以下内容为笔者生产环境的监控,安装都是经过一步步测试的-------------------------------- ...
- Debain下解决sublime无法输入中文
sublime安装的方法在此不做过多介绍,网上有很多中教程的方式.本文描述在已经安装sublime的前提下如何输入中文. 1.保存下面的代码到文件sublime_imfix.c(位于~目录) #inc ...
- shell比较两个字符串是否相等
比较两个字符串是否相等的办法是: if [ "$test"x = "test"x ]; then这里的关键有几点:1 使用单个等号2 注意到等号两边各有一个空格 ...