|
|
Questions and answers for Controls ToolBar.
|
66. Controls ToolBar
|
| 66.1 How do I determine
which button in a ToolBar is clicked ?
|
| 66.2 How can I apply a
Style to a Menu control on a ToolBar ?
|
| 66.3 When I tab into a
toolbar in WPF I can't tab out again ? What can I do to change this tab
behavior ?
|
66.1 How do I determine which button in a ToolBar is clicked ?
|
|
When a button is clicked on a ToolBar, the click is sent to the ToolBar not the
button. In the "ToolBar.ButtonClick" event handler, you need to add code to
check the "Button" property of the "ToolBarButtonClickEventArgs" passed to the
event handler, to determine which button was clicked.
|
[C#]
using System.Windows.Forms;
private void toolBar1_ButtonClick( object sender, ToolBarButtonClickEventArgs e
)
{
if ( e.Button == toolBarButton1 )
MessageBox.Show( "One" );
else if ( e.Button == toolBarButton2 )
MessageBox.Show( "Two" );
else if ( e.Button == toolBarButton3 )
MessageBox.Show( "Three" );
else
MessageBox.Show( "Unknown" );
}
|
66.2 How can I apply a Style to a Menu control on a ToolBar ?
|
|
You can use the "WindowState" property of the "PrintPreviewDialog" class to
maximize the PrintPreview window. To handle zooming, the PrintPreview Dialog
uses a property of the PrintPreview control. PrintPreviewControl contains a
"Zoom" property that allows you to set the zoom factor of the PrintPreview.
|
66.3 When I tab into a toolbar in WPF I can't tab out again ? What can I do to
change this tab behavior ?
|
|
One common way of moving the focus around in a user interface on Windows is to
use the Tab key to move sequentially between the controls. The contents of a
WPF toolbar seems to act like a kind of tabbing black-hole. The focus goes in
there but never comes out again. Try pasting this XAML code into the XAMLPad to
see the problem.
|
[XAML]
<DockPanel>
<ToolBar DockPanel.Dock="Top">
<Button Content="B"
Command="EditingCommands.ToggleBold" />
<Button Content="U"
Command="EditingCommands.ToggleUnderline" />
<Button Content="I"
Command="EditingCommands.ToggleItalic" />
</ToolBar>
<RichTextBox />
</DockPanel>
|
|
Fortunately this can be easily fixed by using the "KeyboardNavigation" attached
property and changing the TabNavigation to "Continue". This allows the tab
focus to move out of the toolbar and back to the other elements of the UI.
|
[XAML]
<DockPanel>
<ToolBar DockPanel.Dock="Top"
KeyboardNavigation.TabNavigation="Continue">
<Button Content="B"
Command="EditingCommands.ToggleBold" />
<Button Content="U"
Command="EditingCommands.ToggleUnderline" />
<Button Content="I"
Command="EditingCommands.ToggleItalic" />
</ToolBar>
<RichTextBox />
</DockPanel>
|
|