我Wizard
使用Xceed的扩展 WPF 工具包创建了一个,需要将Next 按钮的属性设置为(按下时单击按钮)。IsDefault
true
Enter
我们有一个用户凭据页面,单击下一步按钮可验证凭据并执行其他操作。我希望页面表现得像人们期望的那样,输入凭据并按Enter继续。查看文档,似乎为内置按钮公开的唯一按钮属性是Visibility
和Content
。我不知道如何访问那些内置向导按钮上的按钮类的所有其他可用属性。
我Wizard
使用Xceed的扩展 WPF 工具包创建了一个,需要将Next 按钮的属性设置为(按下时单击按钮)。IsDefault
true
Enter
我们有一个用户凭据页面,单击下一步按钮可验证凭据并执行其他操作。我希望页面表现得像人们期望的那样,输入凭据并按Enter继续。查看文档,似乎为内置按钮公开的唯一按钮属性是Visibility
和Content
。我不知道如何访问那些内置向导按钮上的按钮类的所有其他可用属性。
该Wizard
控件不公开任何属性来设置默认按钮。但是,您可以从 GitHub复制默认样式并进行如下调整。我为Next和FinishIsDefault
设置了属性。
将此样式复制到任何父资源字典。由于它是隐式样式,它将自动应用于Wizard
范围内的所有 s。您也可以添加一个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>
如果您需要更灵活的方法,则必须创建一个自定义控件,该控件派生自Wizard
该控件公开一个依赖属性,例如按钮的枚举类型,以便能够指定默认按钮。然后,您可以在控件中获取模板部分(按钮),并IsDefault
在依赖属性的属性更改回调中相应地设置它们的属性。