Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.net Avalonia中更改窗口背景色的更简单方法';什么是系统顶栏?_C#_.net Core_Avaloniaui - Fatal编程技术网

C# 在.net Avalonia中更改窗口背景色的更简单方法';什么是系统顶栏?

C# 在.net Avalonia中更改窗口背景色的更简单方法';什么是系统顶栏?,c#,.net-core,avaloniaui,C#,.net Core,Avaloniaui,在dotnet的框架中。 我使用的是一个黑暗的用户界面,我设法让一切都变得黑暗,但有一件事:Windows操作系统中的窗口系统顶部栏 我已经看到,我可以设置属性HasSystemDecorations=“false”,使其消失,但随后我必须使用拖动功能、标题、关闭、最大化、最小化等实现顶部栏,当我只想更改背景色时,这是一种痛苦 让窗口顶部栏更改为深色背景色的更简单方法是什么 如果唯一的方法是使用HasSystemDecorations,那么实现具有关闭/最小化/最大化/拖动功能的黑色顶部栏的最简

在dotnet的框架中。 我使用的是一个黑暗的用户界面,我设法让一切都变得黑暗,但有一件事:Windows操作系统中的窗口系统顶部栏

我已经看到,我可以设置属性
HasSystemDecorations=“false”
,使其消失,但随后我必须使用拖动功能、标题、关闭、最大化、最小化等实现顶部栏,当我只想更改背景色时,这是一种痛苦

让窗口顶部栏更改为深色背景色的更简单方法是什么


如果唯一的方法是使用
HasSystemDecorations
,那么实现具有关闭/最小化/最大化/拖动功能的黑色顶部栏的最简单示例是什么?

是的,您必须设置
HasSystemDecorations=“false”
并实现自己的标题栏。我有一个关于如何使用0.10版和fluent主题实现这一点的基本模板

这实际上相当容易,因为Avalonia提供了许多方便的方法来实现这一点

概述:

设置

然后实现一个标题栏。例如,“关闭”按钮可能如下所示:

<Button Width="46"
        VerticalAlignment="Stretch"
        BorderThickness="0"
        Name="CloseButton"
        ToolTip.Tip="Close">
    <Button.Resources>
      <CornerRadius x:Key="ControlCornerRadius">0</CornerRadius>
    </Button.Resources>
    <Button.Styles>
      <Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
        <Setter Property="Background" Value="Red"/>
      </Style>
      <Style Selector="Button:not(:pointerover) /template/ ContentPresenter#PART_ContentPresenter">
        <Setter Property="Background" Value="Transparent"/>
      </Style>
      <Style Selector="Button:pointerover > Path">
        <Setter Property="Fill" Value="White"/>
      </Style>
      <Style Selector="Button:not(:pointerover) > Path">
        <Setter Property="Fill" Value="{DynamicResource SystemControlForegroundBaseHighBrush}"/>
      </Style>
    </Button.Styles>
    <Path Margin="10,0,10,0"
          Stretch="Uniform"
          Data="M1169 1024l879 -879l-145 -145l-879 879l-879 -879l-145 145l879 879l-879 879l145 145l879 -879l879 879l145 -145z"></Path>
  </Button>

现在,您显然仍然需要模拟按钮的行为。原则上可以这样做(再次查看上面的Github回购协议,了解具体示例):


实际上,在上面的代码片段中还有一个细节需要注意。至少在windows上,最大化的窗口实际上比屏幕大。如果你不想让你的内容超出屏幕的界限,你需要在窗口的主控件中添加一个边距。因此,
主机窗口的
填充
会相应更改。

是的,您必须设置
hassystemdecordentials=“false”
,并实现自己的标题栏。我有一个关于如何使用0.10版和fluent主题实现这一点的基本模板

这实际上相当容易,因为Avalonia提供了许多方便的方法来实现这一点

概述:

设置

然后实现一个标题栏。例如,“关闭”按钮可能如下所示:

<Button Width="46"
        VerticalAlignment="Stretch"
        BorderThickness="0"
        Name="CloseButton"
        ToolTip.Tip="Close">
    <Button.Resources>
      <CornerRadius x:Key="ControlCornerRadius">0</CornerRadius>
    </Button.Resources>
    <Button.Styles>
      <Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
        <Setter Property="Background" Value="Red"/>
      </Style>
      <Style Selector="Button:not(:pointerover) /template/ ContentPresenter#PART_ContentPresenter">
        <Setter Property="Background" Value="Transparent"/>
      </Style>
      <Style Selector="Button:pointerover > Path">
        <Setter Property="Fill" Value="White"/>
      </Style>
      <Style Selector="Button:not(:pointerover) > Path">
        <Setter Property="Fill" Value="{DynamicResource SystemControlForegroundBaseHighBrush}"/>
      </Style>
    </Button.Styles>
    <Path Margin="10,0,10,0"
          Stretch="Uniform"
          Data="M1169 1024l879 -879l-145 -145l-879 879l-879 -879l-145 145l879 879l-879 879l145 145l879 -879l879 879l145 -145z"></Path>
  </Button>

现在,您显然仍然需要模拟按钮的行为。原则上可以这样做(再次查看上面的Github回购协议,了解具体示例):

实际上,在上面的代码片段中还有一个细节需要注意。至少在windows上,最大化的窗口实际上比屏幕大。如果你不想让你的内容超出屏幕的界限,你需要在窗口的主控件中添加一个边距。因此,
hostWindow
Padding
会相应地更改

<DockPanel Background="Black"
           IsHitTestVisible="False"
           Name="TitleBarBackground"></DockPanel>
minimizeButton = this.FindControl<Button>("MinimizeButton");
maximizeButton = this.FindControl<Button>("MaximizeButton");
maximizeIcon = this.FindControl<Path>("MaximizeIcon");
maximizeToolTip = this.FindControl<ToolTip>("MaximizeToolTip");
closeButton = this.FindControl<Button>("CloseButton");
windowIcon = this.FindControl<Image>("WindowIcon");

minimizeButton.Click += MinimizeWindow;
maximizeButton.Click += MaximizeWindow;
closeButton.Click += CloseWindow;
windowIcon.DoubleTapped += CloseWindow;

private void CloseWindow(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
      Window hostWindow = (Window)this.VisualRoot;
      hostWindow.Close();
}

private void MaximizeWindow(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
     Window hostWindow = (Window)this.VisualRoot;

     if (hostWindow.WindowState == WindowState.Normal)
     {
           hostWindow.WindowState = WindowState.Maximized;
     }
     else
     {
           hostWindow.WindowState = WindowState.Normal;
     }
}

private void MinimizeWindow(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
      Window hostWindow = (Window)this.VisualRoot;
      hostWindow.WindowState = WindowState.Minimized;
}
private async void SubscribeToWindowState()
{
        Window hostWindow = (Window)this.VisualRoot;

        while (hostWindow == null)
        {
            hostWindow = (Window)this.VisualRoot;
            await Task.Delay(50);
        }

        hostWindow.GetObservable(Window.WindowStateProperty).Subscribe(s =>
        {
            if (s != WindowState.Maximized)
            {
                maximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 2048v-2048h-2048v2048h2048zM1843 1843h-1638v-1638h1638v1638z");
                hostWindow.Padding = new Thickness(0,0,0,0);
                maximizeToolTip.Content = "Maximize";
            }
            if (s == WindowState.Maximized)
            {
                maximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 1638h-410v410h-1638v-1638h410v-410h1638v1638zm-614-1024h-1229v1229h1229v-1229zm409-409h-1229v205h1024v1024h205v-1229z");
                hostWindow.Padding = new Thickness(7,7,7,7);
                maximizeToolTip.Content = "Restore Down";
            }
        });
    }