gpt4 book ai didi

c# - 绑定(bind)键绑定(bind)的键属性

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:39 25 4
gpt4 key购买 nike

This question提供了一种干净的方法,用于将窗口级别的键绑定(bind)到 XAML 中的 ViewModel 命令。这非常棒,但它不允许自定义所使用的 key 。是否可以将“键”值绑定(bind)到 View 模型,如果可以,csharp 中的“键”是什么类型的值?

<Window.InputBindings>
<KeyBinding Key="{Binding RefreshKey}"
Command="{Binding RefreshCommand}" />

或者是否可以在代码中添加窗口级键绑定(bind)?同样的问题有一个将它放在代码隐藏中的解决方案,但如果可能的话,我更愿意将代码保留在 ViewModel 中。

最佳答案

http://msdn.microsoft.com/en-us/library/system.windows.input.keygesture.aspx

For KeyGesture XAML usages, the property that is generally set in XAML is Gesture, in cases where the gesture represents both a standard key and a modifier key

... Note that the XAML usage does not directly declare a element. That object element usage is not possible because KeyGesture does not expose a public default constructor. Instead, the XAML usage uses the typeconverter behavior to declare an entire KeyGesture inline as the Gesture attribute value.

我认为你可以返回一个 KeyGesture 对象来绑定(bind)一个 Key 属性,或者你总是可以返回一个组合字符串,它会自动转换

关于c# - 绑定(bind)键绑定(bind)的键属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7972625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com