1

Good evening. I have been researching my issue for about two days now, and have tried at least a dozen variations of the problem. Every single last one of them has been a complete total failure, so I won't bother posting any code here.

What I need is a StackPanel for a Border-less Window. The StackPanel needs to have an opaque background, and the children need to have a transparent background. I need the transparency to carry ALL the way through the child element, StackPanel, and underlying main window.

Does anyone have any idea as to how to go about this, and where I should start? I am an intermediate level programmer, and have hit a solid wall here. I have tried to inherit from Panel Class, over-riding the usual suspects; MeasureOverride, ArangeOveride, OnRender, etc..

One of the thoughts I also had, was using some form or another of CombinedGeometry between the parent, and all child nodes.

Thanks in advance!!

4

2 回答 2

0

What you are probably missing is Window.AllowsTransparency="True". Sad to say that you have to build your own window title and border because WindowStyle property must be set to None.

I've created a sample for you:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        AllowsTransparency="True"
        Background="Transparent"
        WindowStyle="None"
        WindowStartupLocation="CenterScreen">
    <Border BorderBrush="Black" BorderThickness="1">        
        <DockPanel>
            <Menu DockPanel.Dock="Top">
                <MenuItem Header="Application">
                    <MenuItem Header="_Close" Click="MenuItem_Click"/>
                </MenuItem>
            </Menu>
            <ToolBar DockPanel.Dock="Bottom">
                <Button>sample button</Button>
            </ToolBar>
            <StackPanel>
                ... your whiteboard ...
            </StackPanel>
        </DockPanel>
    </Border>
</Window>

.

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}
于 2012-05-17T09:23:02.023 回答
0

好的,所以经过许多小时的蛮力“黑客攻击”,我设法找到了一种方法来完成我所需要的。

<Border Name="OuterBorder" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Orange" BorderThickness="1.5">
    <Border Name="FillerStrip" BorderBrush="Black" BorderThickness="20">
        <Border Name="InnerBorder" BorderBrush="Orange" BorderThickness="1.5">
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
                <local:GlassBoardControl BorderBrush="Orange"            BorderThickness="2" AxisBrush="LawnGreen" AxisThickness="15" x:Name="screen" />

            </StackPanel>
        </Border>    
    </Border>
</Border>

现在我唯一的问题是我到底该如何创建一个自定义面板作为它的边框?关于我应该从哪里开始的任何想法将不胜感激。

于 2012-05-19T08:13:05.690 回答