Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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# 消失xaml按钮-wpf_C#_Wpf_Xaml_Button - Fatal编程技术网

C# 消失xaml按钮-wpf

C# 消失xaml按钮-wpf,c#,wpf,xaml,button,C#,Wpf,Xaml,Button,我的申请行为很奇怪。我在窗口中显示九个按钮,但有时一个或两个按钮消失。这是不正常的。有时按钮包含一个部分(小矩形或内容) App.xaml <Application.Resources> <Style TargetType="{x:Type Button}" x:Key="BiletButton1a"> <Setter Property="Background" Value="White"/> <Setter Pr

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

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>



我建议您创建一种样式并应用于多个按钮。按钮相似但不相同。为什么需要这么多几乎相同的样式?尝试使用BasedOn样式属性OK我尝试使用BasedOn,但我认为这不会解决问题。显示按钮的容器。