简体   繁体   English

扩展 WPF 工具包向导 - 为下一步按钮设置 IsDefault = true

[英]Extended WPF Toolkit Wizard - Set IsDefault = true for Next button

I've created a Wizard using the Extended WPF Toolkit by Xceed and need to set the IsDefault property of the Next button to true (Clicks button when Enter is pressed).我使用Xceed扩展 WPF 工具包创建了一个Wizard ,需要将 Next 按钮的IsDefault属性设置为true (按下Enter时单击按钮)。

We have a user credentials page where clicking the Next button validates the credentials and performs other actions.我们有一个用户凭据页面,单击下一步按钮可验证凭据并执行其他操作。 I'd like the the page to behave like people would expect, type in credentials and press Enter to continue.我希望页面表现得像人们期望的那样,输入凭据并按Enter继续。 Looking through the documentation, the only button properties that seem to be exposed for the built-in buttons are Visibility and Content .查看文档,似乎为内置按钮公开的唯一按钮属性是VisibilityContent I can't figure out how to access all the other available properties for the Button Class on those built-in Wizard Buttons.我不知道如何访问那些内置向导按钮上的按钮 Class 的所有其他可用属性。

The Wizard control does not expose any property to set the default button. Wizard控件不公开任何属性来设置默认按钮。 However, you can copy the default style from GitHub and adapt it like below.但是,您可以从 GitHub 复制默认样式,并像下面这样进行调整。 I set the IsDefault property for Next and Finish .我为NextFinish设置了IsDefault属性。

Copy this style to any parent resource dictionary.将此样式复制到任何父资源字典。 As it is and implicit style, it will be applied automatically to all Wizard s in scope.由于它是隐式风格,它将自动应用于 scope 中的所有Wizard You can alternatively add an x:Key and reference it explicitly.您也可以添加一个x:Key并明确引用它。

<Style TargetType="{x:Type xctk:Wizard}">
   <Style.Resources>
      <xctk:WizardPageButtonVisibilityConverter x:Key="WizardPageButtonVisibilityConverter"/>
   </Style.Resources>
   <Setter Property="Background" Value="Transparent" />
   <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}"/>
   <Setter Property="BorderThickness" Value="1" />
   <Setter Property="ItemsPanel">
      <Setter.Value>
         <ItemsPanelTemplate>
            <Grid/>
         </ItemsPanelTemplate>
      </Setter.Value>
   </Setter>
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type xctk:Wizard}">
            <Border Background="{TemplateBinding Background}"
                             BorderBrush="{TemplateBinding BorderBrush}"
                             BorderThickness="{TemplateBinding BorderThickness}"
                             Padding="{TemplateBinding Padding}">
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="*" />
                     <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>

                  <ContentPresenter Content="{Binding CurrentPage, RelativeSource={RelativeSource TemplatedParent}}" />

                  <Border Grid.Row="1"
                                   BorderBrush="{TemplateBinding BorderBrush}"
                                   BorderThickness="0,1,0,0"
                                   Padding="7">
                     <StackPanel>
                        <Grid>
                           <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="*" />
                           </Grid.ColumnDefinitions>
                           <Button Name="HelpButton"
                                            Grid.Column="0"
                                            MinWidth="75"
                                            Command="xctk:WizardCommands.Help"
                                            Content="{TemplateBinding HelpButtonContent}">
                              <Button.Visibility>
                                 <MultiBinding Converter="{StaticResource WizardPageButtonVisibilityConverter}">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                      Path="HelpButtonVisibility"/>
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                      Path="CurrentPage.HelpButtonVisibility"/>
                                 </MultiBinding>
                              </Button.Visibility>
                           </Button>
                           <StackPanel Grid.Column="1"
                                                Orientation="Horizontal"
                                                HorizontalAlignment="Right">
                              <Button Name="BackButton"
                                               MinWidth="75"
                                               Command="xctk:WizardCommands.PreviousPage"
                                               Content="{TemplateBinding BackButtonContent}">
                                 <Button.Visibility>
                                    <MultiBinding Converter="{StaticResource WizardPageButtonVisibilityConverter}">
                                       <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                         Path="BackButtonVisibility"/>
                                       <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                         Path="CurrentPage.BackButtonVisibility"/>
                                    </MultiBinding>
                                 </Button.Visibility>
                              </Button>
                              <Grid MinWidth="75"
                                             Margin="2,0,0,0">
                                 <Button Name="NextButton"
                                                  IsDefault="True"
                                                  Command="xctk:WizardCommands.NextPage"
                                                  Content="{TemplateBinding NextButtonContent}">
                                    <Button.Visibility>
                                       <MultiBinding Converter="{StaticResource WizardPageButtonVisibilityConverter}">
                                          <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                            Path="NextButtonVisibility"/>
                                          <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                            Path="CurrentPage.NextButtonVisibility"/>
                                       </MultiBinding>
                                    </Button.Visibility>
                                 </Button>
                                 <Button Name="FinishButton"
                                                  IsDefault="True"
                                                  Command="xctk:WizardCommands.Finish"
                                                  Content="{TemplateBinding FinishButtonContent}">
                                    <Button.Visibility>
                                       <MultiBinding Converter="{StaticResource WizardPageButtonVisibilityConverter}">
                                          <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                            Path="FinishButtonVisibility"/>
                                          <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                            Path="CurrentPage.FinishButtonVisibility"/>
                                       </MultiBinding>
                                    </Button.Visibility>
                                 </Button>
                              </Grid>
                              <Button Name="CancelButton"
                                               Margin="7,0,0,0"
                                               MinWidth="75"
                                               Command="xctk:WizardCommands.Cancel"
                                               Content="{TemplateBinding CancelButtonContent}">
                                 <Button.Visibility>
                                    <MultiBinding Converter="{StaticResource WizardPageButtonVisibilityConverter}">
                                       <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                         Path="CancelButtonVisibility"/>
                                       <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                                         Path="CurrentPage.CancelButtonVisibility"/>
                                    </MultiBinding>
                                 </Button.Visibility>
                              </Button>
                           </StackPanel>
                        </Grid>
                     </StackPanel>
                  </Border>
               </Grid>
            </Border>
            <ControlTemplate.Triggers>
               <Trigger Property="IsEnabled" Value="True" SourceName="FinishButton">
                  <Setter Property="Visibility" Value="Visible" TargetName="FinishButton"/>
               </Trigger>
            </ControlTemplate.Triggers>
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>

If you need a more flexible approach, you will have to create a custom control derived from Wizard that exposes a dependency property, eg of an enum type for the button, to be able to specify the default button.如果您需要更灵活的方法,则必须创建一个从Wizard派生的自定义控件,该控件公开一个依赖属性,例如按钮的枚举类型,以便能够指定默认按钮。 You could then get the template parts (the buttons) in the control and set their IsDefault property accordingly in the property changed callback of the dependency property.然后,您可以在控件中获取模板部分(按钮)并在依赖属性的属性更改回调中相应地设置它们的IsDefault属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM