Style中的Page的InputBindings并添加键绑定

时间:2017-10-03 16:24:59

标签: wpf mvvm styles key-bindings

我有很多相同的以下类型的网页:

<Page x:Class="DP.View.DepartmentsView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Style="{StaticResource PageC}">
<!--<Page.InputBindings>
    <KeyBinding Modifiers="Ctrl" Key="F" Command="{Binding FindCommand}" CommandParameter=""/>
    <KeyBinding Modifiers="Ctrl" Key="P" Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=DG}"/>
</Page.InputBindings>-->
<Grid Background="LightGray">
    <DataGrid Style="{StaticResource DataGridC}" x:Name="DG"/>
</Grid>

我希望以样式绑定KeyBinding

风格有什么问题?:

<Style x:Key="PageC" TargetType="Page" >
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type Page}">
            <Page>
                <Page.InputBindings>
                    <KeyBinding Modifiers="Ctrl" Key="F" Command="{Binding FindCommand}" CommandParameter=""/>
                    <KeyBinding Modifiers="Ctrl" Key="P" Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=DG}"/>
                </Page.InputBindings>
            </Page>
        </ControlTemplate>
    </Setter.Value>
</Setter>

0 个答案:

没有答案