WindowChrome,AllowTransparency = true,WindowStyle =无问题

时间:2015-06-16 13:20:02

标签: wpf multiscreen window-chrome

我有一个应用程序,我用windowchrome覆盖主shell样式,如下所示:

XAML:

    <Style TargetType="{x:Type local:MainLayoutWindow}">
    <Setter Property="shell:WindowChrome.WindowChrome">
        <Setter.Value>
            <shell:WindowChrome 
                    GlassFrameThickness="0"
                    ResizeBorderThickness="7"
                    CaptionHeight="36"
                    CornerRadius="3"                    
                    />
        </Setter.Value>
    </Setter>
    <Setter Property="WindowState" Value="Maximized" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MainLayoutWindow}">
                <Border>
                    <Border.Style>
                        <Style TargetType="{x:Type Border}">
                            <Setter Property="BorderThickness" Value="{Binding WindowResizeBorderThickness}"/>
                        </Style>
                    </Border.Style>
                    <Grid x:Name="Root" >

                        <Grid>
                            <!-- Content Border -->

                            <!-- Header -->

                        </Grid>
                        <!-- Buttons -->
                        <Border BorderBrush="{StaticResource WindowButtonOutline}" BorderThickness="1,0,1,1" CornerRadius="0,0,3,3" VerticalAlignment="Top" Margin="7,1,0,0" HorizontalAlignment="Left">
                            <StackPanel Orientation="Horizontal">

                                <Button x:Name="PART_btnClose"   Height="17" Width="35" IsTabStop="False" shell:WindowChrome.IsHitTestVisibleInChrome="True" >

                                </Button>
                                <Button x:Name="PART_btnMaxAndNormal" Height="17" Width="24" IsTabStop="False" shell:WindowChrome.IsHitTestVisibleInChrome="True" >

                                </Button>
                                <Button x:Name="PART_btnMinimize"   Height="17" Width="24" IsTabStop="False" shell:WindowChrome.IsHitTestVisibleInChrome="True" >

                                </Button>

                            </StackPanel>


                        </Border>
                    </Grid>
                </Border>

                <ControlTemplate.Triggers>

                    <Trigger Property="WindowState" Value="Maximized">
                        <Setter Property="shell:WindowChrome.WindowChrome">
                            <Setter.Value>
                                <shell:WindowChrome ResizeBorderThickness="0"/>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="WindowState" Value="Normal">
                        <Setter Property="shell:WindowChrome.WindowChrome">
                            <Setter.Value>
                                <shell:WindowChrome ResizeBorderThickness="7"/>
                            </Setter.Value>
                        </Setter>
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

CS:

    public MyWindow()
    {
        this.AllowsTransparency = true;
        this.WindowStyle = System.Windows.WindowStyle.None;
        this.Caption = "some text";
        this.StateChanged += MainLayoutWindow_StateChanged;
    }

    void MainLayoutWindow_StateChanged(object sender, EventArgs e)
    {
        if (this._myVM== null) return;
        this._myVM.SetState(this.WindowState);
    }

    public MyWindow(MyVM myVM)
        : this()
    {
        this.DataContext = mainVM;
        this._myVM= myVM;
    }

    Thickness _maximizeThickness = new Thickness(8, 8, 8, 8);
    Thickness _normalThickness = new Thickness(0, 0, 0, 0);
    Thickness _windowResizeBorderThickness = new Thickness(0, 0, 0, 0);
    const string WINDOWRESIZEBORDERTICKNESS = "WindowResizeBorderThickness";
    public Thickness WindowResizeBorderThickness
    {
        get
        {
            return _windowResizeBorderThickness;
        }
        set
        {
            if (_windowResizeBorderThickness != value)
            {
                _windowResizeBorderThickness = value;
                OnPropertyChanged(WINDOWRESIZEBORDERTICKNESS);
            }
        }
    }

    public void SetState(WindowState windowState)
    {
        if (windowState == WindowState.Maximized)
        {
            WindowResizeBorderThickness = _maximizeThickness;
        }
        else
        {
            WindowResizeBorderThickness = _normalThickness;
        }
    }

的问题:

  1. 如果我不使用AllowsTransparency = trueWindowStyle=None,似乎有时会在加载样式之前看到原始按钮。或者如果对服务器采取任何需要很长时间的操作。
  2. 如果我设置了AllowsTransparency = trueWindowStyle=None,那么该应用将占据屏幕的所有宽度和高度(任务栏未显示)。
  3. 对于多个屏幕,当应用程序在主屏幕上以最大化模式打开时,我移动到辅助屏幕,最大模式ID执行但是我不能从辅助屏幕到主屏幕,它不允许移动到最大化模式。
  4. 有什么想法吗?感谢

0 个答案:

没有答案