Lou*_*ann 22
当然,但你必须自己重拍这些按钮(这并不难,不用担心).
在您的MainWindow.xaml中:
<Window ...
Title="" Height="Auto" Width="Auto" Icon="../Resources/MyIcon.ico"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
WindowStyle="None" AllowsTransparency="True" Background="Transparent"
...>
<Canvas>
<Button /> <!-- Close -->
<Button /> <!-- Minimize -->
<Button /> <!-- Maximize -->
<TabControl>
...
</TabControl>
</Canvas>
</Window>
Run Code Online (Sandbox Code Playgroud)
然后你只需将Buttons和TabControl放在Canvas上,并自定义外观.
编辑:在.NET 4.5中关闭/最大化/最小化的内置命令是SystemCommands.CloseWindowCommand/
SystemCommands.MaximizeWindowCommand/SystemCommands.MinimizeWindowCommand
因此,如果您使用的是.NET 4.5,则可以执行以下操作:
<Window ...
Title="" Height="Auto" Width="Auto" Icon="../Resources/MyIcon.ico"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
WindowStyle="None" AllowsTransparency="True" Background="Transparent"
...>
<Window.CommandBindings>
<CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute_1" Executed="CommandBinding_Executed_1" />
<CommandBinding Command="{x:Static SystemCommands.MaximizeWindowCommand}" CanExecute="CommandBinding_CanExecute_1" Executed="CommandBinding_Executed_2" />
<CommandBinding Command="{x:Static SystemCommands.MinimizeWindowCommand}" CanExecute="CommandBinding_CanExecute_1" Executed="CommandBinding_Executed_3" />
</Window.CommandBindings>
<Canvas>
<Button Command="{x:Static SystemCommands.CloseWindowCommand}" Content="Close" />
<Button Command="{x:Static SystemCommands.MaximizeWindowCommand}" Content="Maximize" />
<Button Command="{x:Static SystemCommands.MinimizeWindowCommand}" Content="Minimize" />
<TabControl>
...
</TabControl>
</Canvas>
</Window>
Run Code Online (Sandbox Code Playgroud)
在你的C#代码隐藏中:
private void CommandBinding_CanExecute_1(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.CloseWindow(this);
}
private void CommandBinding_Executed_2(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.MaximizeWindow(this);
}
private void CommandBinding_Executed_3(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.MinimizeWindow(this);
}
Run Code Online (Sandbox Code Playgroud)
这将使得关闭/最大化/最小化工作与常规窗口完全相同.
当然,您可能希望使用System.Windows.Interactivity将C#移动到ViewModel中.