我有一個碼頭上的telerik關閉按鈕,我想重寫樣式以允許用戶選擇他們想要關閉的選項。覆蓋Telerik關閉按鈕
以記事本+ +爲例..有一個「關閉」和「關閉所有,但這個」選項。
這正是我想要做的這個telerik radDock關閉按鈕。
我已經研究過這個,找不到任何有用的東西讓我真正開始。我剛開始使用WPF(以及真正的C#),所以任何有用的建議,代碼或示例項目將不勝感激。先進的謝謝你。
Metro Smurf,它與這個教程非常相似。我對WPF和C#很新,所以請好好哈哈。
這是我的XAML:
<Window x:Class="RadDockCloseButton1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="ContextMenuTemplate">
<telerik:RadContextMenu InheritDataContext="False">
<telerik:RadMenuItem
IsChecked="{Binding IsFloatingOnly}"
Command="telerik:RadDockingCommands.Floating"
CommandParameter="{Binding}"
CommandTarget="{Binding}"
Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}"/>
<telerik:RadMenuItem
IsChecked="{Binding IsDockableOptionChecked}"
Command="telerik:RadDockingCommands.Dockable"
CommandParameter="{Binding}"
CommandTarget="{Binding}"
Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}" />
<telerik:RadMenuItem
Command="local:RadDockingCommands.CloseAllButThisCommand"
CommandParameter="{Binding}"
CommandTarget="{Binding}"
Header="{Binding Command.Text, RelativeSource={RelativeSource Self}}" />
</telerik:RadContextMenu>
</DataTemplate>
<Style TargetType="telerik:RadPane">
<Setter Property="ContextMenuTemplate" Value="{StaticResource ContextMenuTemplate}" />
</Style>
</Window.Resources>
<Grid>
<telerik:RadDocking x:Name="radDocking">
<telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer>
<telerik:RadPaneGroup x:Name="radPaneGroup">
<telerik:RadPane TitleTemplate="{StaticResource ContextMenuTemplate}" Title="Pane 1">
<TextBlock Text="Some simple text here"/>
</telerik:RadPane>
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking.DocumentHost>
</telerik:RadDocking>
</Grid>
</Window>
這裏是我的C#:
using System.Windows;
namespace RadDockCloseButton1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public static class RadDockingCommands
{
private static RoutedUICommand closeAllPanesButThisCommand;
public static RoutedUICommand CloseAllPanesButThisCommand
{
get
{
if (closeAllPanesButThisCommand == null)
{
closeAllPanesButThisCommand = new RoutedUICommand("Close all panes but this", "CloseAllPanesButThisCommand", typeof(RadDockingCommands));
}
return closeAllPanesButThisCommand;
}
}
public static void OnCloseAllPanesButThis(object sender, ExecutedRoutedEventArgs e)
{
var pane = e.Parameter as RadPane;
if (pane != null)
{
var paneGroup = pane.PaneGroup;
if (paneGroup != null)
{
var panesToClose = paneGroup.EnumeratePanes().Where(x => !x.IsHidden && x.IsPinned);
foreach (var paneToClose in panesToClose)
{
if (paneToClose != pane)
{
paneToClose.IsHidden = true;
}
}
}
}
}
public static void OnCloseAllPanesButThisCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
var paneGroup = sender as RadPaneGroup;
if (paneGroup != null)
{
int childrenCount = paneGroup.EnumeratePanes().Count(x => !x.IsHidden && x.IsPinned);
if (childrenCount > 1)
{
e.CanExecute = true;
}
else
{
e.CanExecute = false;
}
}
}
}
}
}
這聽起來更像你是想上下文菜單添加到對接選項卡,再:這是記事本+ +是如何工作的。或者你想添加2個「關閉」按鈕? –
是的,這聽起來是對的。我只是希望它是一個可點擊的工具提示,而不是右鍵單擊,然後選擇執行此操作的方法。你知道關於添加上下文菜單到radDock關閉按鈕的任何事嗎? – JLott
您可以使用[Telerik如何禁用(隱藏)關閉按鈕](http://www.telerik.com/help/wpf/raddocking-how-to-disable-the-close-button.html)。然後使用[Telerik如何添加按鈕標題](http://www.telerik.com/help/wpf/raddocking-how-to-add-buttons-to-the-pane-headers.html)。或者使用[Telerik如何將菜單項添加到RadPane](http://www.telerik.com/help/wpf/raddocking-how-to-add-menu-items-to-the-radpanes-menu.html) 。我已經將它們用於類似的場景。如果你能更清楚地描述你想要達到的目標,我可能會有更具體的想法。 –