消失xaml按钮 - wpf

时间:2014-08-27 07:15:14

标签: c# wpf xaml button

我的应用程序有奇怪的行为。我在窗口中显示九个按钮,但有时一个或两个按钮消失。这不常见。有时按钮包含一个部分(小矩形或内容)。

的App.xaml

<Application.Resources>
    <Style TargetType="{x:Type Button}" x:Key="BiletButton1a">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">              
                    <Grid>
                        <Rectangle   Fill="{TemplateBinding Background}">
                            <Rectangle.Effect>
                                <DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="#E23817" HorizontalAlignment="Right" Height="133"  Width="18"/>
                        <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center"  />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Button}" x:Key="BiletButton1b">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Rectangle   Fill="{TemplateBinding Background}">
                            <Rectangle.Effect>
                                <DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="#E23817" HorizontalAlignment="Right" VerticalAlignment="Top" Height="67"  Width="18"/>
                        <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center"  />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Button}" x:Key="BiletButton2a">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Rectangle   Fill="{TemplateBinding Background}">
                            <Rectangle.Effect>
                                <DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="#239AD4" HorizontalAlignment="Right" Height="133"  Width="18"/>

                        <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center"  />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style TargetType="{x:Type Button}" x:Key="BiletButton2b">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Rectangle   Fill="{TemplateBinding Background}">
                            <Rectangle.Effect>
                                <DropShadowEffect ShadowDepth="5" Color="Gray" Opacity="0.5"/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="#239AD4" HorizontalAlignment="Right" VerticalAlignment="Top" Height="67"  Width="18"/>
                        <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center"  />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>     
</Application.Resources>

Window1.xaml

    <Button Style="{StaticResource BiletButton1a}" FontSize="30" HorizontalAlignment="Left" Margin="16,328,0,0" x:Name="button_ticket1a" Height="130" Width="226" Click="button_ticket1a_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto"  HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock1a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>  

    <Button Style="{StaticResource BiletButton1b}" FontSize="30" HorizontalAlignment="Left" Margin="16,492,0,0" x:Name="button_ticket1b" Height="130" Width="226" Click="button_ticket1b_Click" VerticalAlignment="Top">
        <Grid >
            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock1b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>
        </Grid>
    </Button>    

    <Button Style="{StaticResource BiletButton2a}" FontSize="30" HorizontalAlignment="Left" Margin="267,330,0,0" x:Name="button_ticket2a" Height="130" Width="226" Click="button_ticket2a_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto"  HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock2a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="267,492,0,0" x:Name="button_ticket2b" Height="130" Width="226" Click="button_ticket2b_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock2b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton2a}" FontSize="30" HorizontalAlignment="Left" Margin="521,330,0,0" x:Name="button_ticket3a" Height="130" Width="226" Click="button_ticket3a_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto"  HorizontalAlignment="Center" VerticalAlignment="Stretch" Name="tblock3a" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="521,492,0,0" x:Name="button_ticket3b" Height="130" Width="226" Click="button_ticket3b_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock3b" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="267,654,0,0" x:Name="button_ticket2c" Height="130" Width="226" Click="button_ticket2c_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock2c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton2b}" FontSize="30" HorizontalAlignment="Left" Margin="521,654,0,0" x:Name="button_ticket3c" Height="130" Width="226" Click="button_ticket3c_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock3c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

    <Button Style="{StaticResource BiletButton1b}" FontSize="30" HorizontalAlignment="Left" Margin="16,654,0,0" x:Name="button_ticket1c" Height="130" Width="226" Click="button_ticket1c_Click" VerticalAlignment="Top">
        <Grid >

            <TextBlock TextWrapping="Wrap" Width="auto" Height="auto" HorizontalAlignment="Center" VerticalAlignment="Center" Name="tblock1c" FontSize="14" FontFamily="verdana" FontWeight="Bold" ></TextBlock>

        </Grid>
    </Button>

</Grid>

0 个答案:

没有答案