【发布时间】:2011-03-02 01:02:20
【问题描述】:
书上说
WPF Button 类只增加了两个 简单的概念在什么之上 ButtonBase 已经提供:作为一个 取消按钮或默认按钮。 这两种机制很方便短 对话的剪辑。 If Button.IsCancel 在 a 内的 Button 上设置为 true 对话框(即,通过 它的 ShowDialog 方法),窗口是 自动关闭 对话结果为假。如果 Button.IsDefault 设置为 true, 按 Enter 会使 Button 变为 除非明确显示焦点,否则单击 带走它。
但是在这个示例窗口中
<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="About WPF Unleashed" SizeToContent="WidthAndHeight"
Background="OrangeRed" >
<StackPanel>
<Label FontWeight="Bold" FontSize="20" Foreground="White">
WPF Unleashed (Version 3.0)
</Label>
<Label> 2006 SAMS Publishing</Label>
<Label>Installed Chapters:</Label>
<ListBox>
<ListBoxItem>Chapter 1</ListBoxItem>
<ListBoxItem>Chapter 2</ListBoxItem>
</ListBox>
<TextBox AcceptsReturn="False">HELLO TEXT</TextBox>
<RadioButton>HELLO RADIO BUTTON</RadioButton>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button IsCancel="True" MinWidth="75" Margin="10">Cancel</Button>
<Button x:Name="OKBUTTON" IsDefault="True" MinWidth="75" Margin="10">OK</Button>
</StackPanel>
<StatusBar>You have successfully registered this product.</StatusBar>
</StackPanel>
</Window>
如果我按 Enter 键甚至单击它,模态窗口(通过 ShowDialog())不会关闭(将返回值放在一边)。 这是书上的错误吗?
【问题讨论】:
-
取消按钮的 Esc 有效吗?
-
不,当我们按下 Esc 或 Enter 时,似乎引发了相应按钮的单击事件。表单不会自动关闭。很不幸,这么简单的概念在本书中写错了。不知道书中有多少错误。
标签: wpf wpf-controls