我正在使用C#.NET WPF开发的应用程序,我在PDF File ToolBar中添加了两个动态按钮。
我想知道如何从包含多个操作的菜单中进行选择,第一次单击将分配给第一个动态按钮,第二次单击分配给第二个动态按钮,第三次单击返回给第一个动态按钮。
以下是截图,解释了我的需求以及我为单个动态按钮开发的代码。
动态按钮的代码 XAML :
<ToggleButton
Width="{StaticResource ToolBarButtonWidth}"
Height="{StaticResource ToolBarButtonWidth}"
Command="{Binding ReapplyAnnotationCommand}"
IsChecked="{Binding IsDrawingActive}"
ToolTip="Ajoute une annotation du type sélectionné">
<TextBlock Style="{Binding AnnotationToolsMenuStyle}" />
</ToggleButton>
<ToggleButton
Width="{StaticResource ToolBarButtonWidth}"
Height="{StaticResource ToolBarButtonWidth}"
Command="{Binding ReapplyAnnotationCommand}"
IsChecked="{Binding IsDrawingActive}"
ToolTip="Ajoute une annotation du type sélectionné">
<TextBlock Style="{Binding AnnotationToolsMenuStyle}" />
</ToggleButton>
C#代码链接到分配给动态按钮的操作:
private void ReapplyAnnotation()
{
this.IsSelectTextActive = false;
this.IsSelectAnnotationActive = false;
if (this.IsInsertCommentaireChecked)
{
this.AddTextAnnot();
}
else if (this.IsHighlightChecked)
{
this.Highlight();
}
else if (this.IsUnderlineChecked)
{
this.Underline();
}
else if (this.IsInsertInfoBulleChecked)
{
this.AddStickyNote();
}
else if (this.IsDrawFreeHandChecked)
{
this.Freehand();
}
else if (this.IsDrawLineChecked)
{
this.Line();
}
else if (this.IsDrawCircleChecked)
{
this.Oval();
}
else if (this.IsDrawRectChecked)
{
this.Rect();
}
else if (this.IsDrawArrowChecked)
{
this.Arrow();
}
}
C#代码,允许我选择要应用于按钮的操作
public bool IsDrawingActive
{
get { return this.isDrawingActive; }
set
{
this.isDrawingActive = value;
this.RaisePropertyChanged(() => this.IsDrawingActive);
}
}
** C#*此代码显示如何取消选择当前工具。
您能告诉我如何做到这一点,以使我实现代码中的任务,该任务使我可以取消选择仅用于第一个按钮的工具吗?
private void UnselectAnyActiveCommand()
{
DisableToggles();
this.IsInsertCommentaireChecked = false;
this.IsHighlightChecked = false;
this.IsUnderlineChecked = false;
this.IsInsertInfoBulleChecked = false;
this.IsDrawFreeHandChecked = false;
this.IsDrawLineChecked = false;
this.IsDrawCircleChecked = false;
this.IsDrawRectChecked = false;
this.IsDrawArrowChecked = false;
}
private void DisableToggles()
{
this.IsPanActive = false;
this.IsSelectTextActive = false;
this.IsSelectAnnotationActive = false;
this.IsDrawingActive = false;
}