私は、いくつかのショートカットキーを自分のWPFボタンにバインドするのに苦労しています。ここボタンキーバインディング[MVVM]
// for each command defined in the database
...
PosCommand cmd = null; // FYI: PosCommand implements ICommand
if (!string.IsNullOrEmpty(group.AssemblyPath))
{
if (System.IO.File.Exists(group.AssemblyPath))
cmd = (PosCommand)Activator.CreateInstance(Assembly.LoadFile(group.AssemblyPath).GetType(group.FullQualifiedName), model);
}
else
{
cmd = (PosCommand)Activator.CreateInstance(Assembly.GetExecutingAssembly().GetType(group.FullQualifiedName), model);
}
if (cmd == null)
continue;
Function function = new Function()
{
Command = cmd,
Name = group.FunctionName,
Description = group.Description,
FunctionCode = group.FunctionCode
};
...
は、C#コードに結合XAMLの抜粋である:
<itemscontrol x:name="functionList" grid.row="0" itemssource="{Binding GroupFunctions}" xmlns:x="#unknown">
<itemscontrol.itemtemplate>
<datatemplate>
<groupbox header="{Binding Group}">
<itemscontrol scrollviewer.horizontalscrollbarvisibility="Disabled" itemssource="{Binding Functions}">
<itemscontrol.itemspanel>
<itemspaneltemplate>
<wrappanel />
</itemspaneltemplate>
</itemscontrol.itemspanel>
<itemscontrol.itemtemplate>
<datatemplate>
<Button MinWidth="91" Height="50" Content="{Binding Name}" ToolTip="{Binding Description}" Command="{Binding Command}"/>
</datatemplate>
</itemscontrol.itemtemplate>
</itemscontrol>
</groupbox>
</datatemplate>
</itemscontrol.itemtemplate>
</itemscontrol>
- [なく十分なものでなければならないだけスニペット]ボタンは、次のコードを使用して動的に構築されます私はいくつかの重要なキーバインディングをボタンに追加しようとしましたが、何の成功もありませんでしたか? Functionクラスを変更して、ボタンのそれぞれについてModifierとKeyのプロパティを含むようにしました。 ModifierとKeyの値をハードコーディングしても、まだ動作したくないのですか?
<Button.InputBindings>
<keybinding modifiers="{Binding Mod}" key="{MyKey}" />
</Button.InputBindings>
誰もこの問題で私を助けてくれませんか? 事前に感謝します!
敬具、
こんにちはFelice、多くのご返信ありがとうございます。私はそれを試してみましょう、あなたに知らせる!種類について –
これは、あなたが書いたすべてのUIコンポーネントのコードビハインドにハンドラを書くよりも、再利用可能なアプローチです –