wpf - 设计师看起来与应用程序不同

时间:2010-12-27 21:26:12

标签: wpf wpf-controls styles

您好 我有奇怪的问题。在Visual Studio设计器中,我的应用程序看起来很正常 - 颜色看起来就像我设置它们。但是,如果我启动一个应用程序,几乎所有主窗口上的控件都会变黑背色

这是我的主窗口的xaml代码(有点长)

<Window x:Class="SensorNetworkWpf.Window1"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowStartupLocation="CenterScreen"
    Title="Diagram Designer"
    Height="850" Width="1251" Background="#200077EF">

<Window.Resources>
    <!--<ContextMenu x:Key="DesignerCanvasContextMenu">
        <MenuItem Header="Paste" Command="{x:Static ApplicationCommands.Paste}">
            <MenuItem.Icon>
                <Image Source="Resources/Images/Paste.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Select All" Command="{x:Static s:DesignerCanvas.SelectAll}"/>
    </ContextMenu>-->
</Window.Resources>

<Grid x:Name="MainGrid"  Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="114"/>
        <RowDefinition Height="628*"/>
        <RowDefinition Height="50"/>
    </Grid.RowDefinitions>





        <!-- Toolbox -->
        <!-- GridSplitter -->

        <!-- Designer -->
    <StackPanel Grid.Row="2" >

    <Grid   Height="30" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
                <Button x:Name="btnArrange"  Grid.Column="0"  Content="Rozmieść" Click="btnArrange_Click" />
        <Button x:Name="btnReset" Grid.Column="1"  Content="Reset" Click="btnReset_Click" />
        <Button x:Name="Start" Grid.Column="2"  Content="Start" Click="Start_Click" />

    </Grid>
        <ProgressBar x:Name="pbProgress" Height="20" Minimum="0" Maximum="100" />
  </StackPanel>
        <GroupBox Header="Diagram" Grid.Row="1" Margin="3,22,0,0">
            <ScrollViewer HorizontalScrollBarVisibility="Auto"
                  VerticalScrollBarVisibility="Auto">
                <Canvas x:Name="MyDesigner"  Background="GhostWhite">

                </Canvas>
            </ScrollViewer>
        </GroupBox>


    <GroupBox Header="Algorytm" HorizontalAlignment="Left" Margin="9,0,0,0" Name="gpAlgorithm" Width="328">
        <StackPanel >
            <RadioButton x:Name="rbSA" Content="Symulowane wyżarzanie" Margin="5,5,0,0" IsChecked="True" Checked="rbSA_Checked"/>
            <RadioButton x:Name="rbSAwT" Content="Symulowane wyżarzanie i trilateracja" Margin="5,5,0,0" Checked="rbSA_Checked" />
            <RadioButton x:Name="MDS" Content="Wielowaymiarowe skalowanie" Margin="5,5,0,0" Checked="rbSA_Checked" />
        </StackPanel>
    </GroupBox>
    <GroupBox Header=" " Margin="346,0,6,0" Name="groupBox1">
        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="145*">

                </ColumnDefinition>
                <ColumnDefinition Width="371*">

                </ColumnDefinition>
                <ColumnDefinition Width="258*"></ColumnDefinition>
                <ColumnDefinition Width="258*"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <GroupBox Header="Temperatura">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Label x:Name="lblStartTemperature"  Content="Startowa:" HorizontalAlignment="Left"/>
                    <Label x:Name="lblFinishTemperature"  Content="Końcowa:" HorizontalAlignment="Left" Grid.Row="1"/>
                    <TextBox x:Name="txtStartTemperature" Grid.Column="1"  TextAlignment="Center"></TextBox>
                    <TextBox x:Name="txtFinishTemperature" Grid.Column="1"  TextAlignment="Center" Grid.Row="1"/>


                </Grid>
            </GroupBox>
            <GroupBox Header="Współczynniki" Grid.Column="1">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="34.04*"></RowDefinition>
                        <RowDefinition Height="34.04*"></RowDefinition>

                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="35.93*"></ColumnDefinition>
                        <ColumnDefinition Width="77.57*"></ColumnDefinition>
                        <ColumnDefinition Width="57*"></ColumnDefinition>
                        <ColumnDefinition Width="57*"></ColumnDefinition>

                    </Grid.ColumnDefinitions>
                    <Label x:Name="lblAlpha"  Content="Alfa:" HorizontalAlignment="Left"/>
                    <Label x:Name="lblBeta"  Content="Beta:" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Center"/>
                    <Label x:Name="lblShift" Content="Przesunięcie:" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="2"/>
                    <Label x:Name="lblRange" Content="Zasięg" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="2" />
                    <TextBox x:Name="txtAlpha" Grid.Column="1"  TextAlignment="Center"></TextBox>
                    <TextBox x:Name="txtBeta" Grid.Column="1" Grid.Row="1" TextAlignment="Center"/>
                    <TextBox x:Name="txtShift" Grid.Column="3" Grid.Row="0"  TextAlignment="Center"/>
                    <TextBox x:Name="txtRange" Grid.Column="3" Grid.Row="1"  TextAlignment="Center" />

                </Grid>
            </GroupBox>
            <GroupBox Header="Sposób rozmieszczenia" Grid.Column="2">
                <StackPanel >
                    <RadioButton x:Name="rbUniform" Content="Jednolicie" Margin="5,5,0,0" IsChecked="True" Checked="rbSA_Checked"/>
                    <RadioButton x:Name="rbNonUniform" Content="Niejednolicie" Margin="5,5,0,0" Checked="rbSA_Checked" />

                </StackPanel>
            </GroupBox>
            <GroupBox Header="Węzły" Grid.Column="3">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Label x:Name="lblAllNodes"  Content="Wszystkie:" HorizontalAlignment="Left"/>
                    <Label x:Name="lblAnchornodes"  Content="Główne:" HorizontalAlignment="Left" Grid.Row="1"/>
                    <TextBox x:Name="txtAllNodes" Grid.Column="1"  TextAlignment="Center"></TextBox>
                    <TextBox x:Name="txtAnchornodes" Grid.Column="1"  TextAlignment="Center" Grid.Row="1"/>


                </Grid>

            </GroupBox>


        </Grid>
    </GroupBox>

</Grid>

1 个答案:

答案 0 :(得分:2)

顶级窗口的背景:

 Background="#200077EF"

没有出现在设计师中,但是当你运行它时它会“流血”,因为网格背景是透明的。

更新:真正的问题似乎是窗口背景的alpha通道。在设计师中,背景的“背后”颜色看起来是白色的,在运行时,背景的“背后”颜色看起来是黑色。由于窗口背景的alpha没有为你做任何事情,为了让设计师和运行时同意只使用一个坚实的窗口背景:

Background="#E0EEFD"

其颜色等于7/8白色+ 1/8#0077EF。