控件在运行时模式下未按预期显示

时间:2016-08-22 10:32:37

标签: wpf xaml

我是WPF的新手。我正在尝试在网格中创建一个按钮。问题是按钮在设计模式下很好地显示。但是在Visual Studio中运行应用程序后,我发现按钮的边框被切割,文本显示效果不佳。

网格

  <Grid   Background="Aqua" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="3*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
                <RowDefinition Height="4*" />
            </Grid.RowDefinitions>
            <Button Content="Arrêt Manuel Perturbation"  Name="btn_TypeArret"   Grid.Row="0" Grid.Column="0">
             </Button>
......

设计模式:

Design mode

运行模式

Running Mode

所有标记

<Window x:Class="IProMSL_WPF.iPro_JustificationArret"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="iPro_JustificationArret" Height="670" Width="920" Loaded="Window_Loaded_1"
     MinHeight="558" MinWidth="764"
    >
<Grid>
    <!--grid principale-->
    <Grid.RowDefinitions>
        <RowDefinition Height="3*" />
        <RowDefinition Height="5*" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>


        <Grid   Background="Aqua" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="3*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
                <RowDefinition Height="4*" />
            </Grid.RowDefinitions>
            <Button ClipToBounds="False" Content="Arrêt Manuel Perturbation"  Name="btn_TypeArret"   Grid.Row="0" Grid.Column="0">
             </Button>
            <Button Content="...." Height="23" HorizontalAlignment="Right" Margin="0,21,41,0" Name="btnClavierdateHeure" VerticalAlignment="Top" Width="57" Grid.Column="2" />
                <Label Content="Heure Fin Arrêt:" Height="28" HorizontalAlignment="Left" Margin="33,21,0,0" Name="lbl_DateFin" VerticalAlignment="Top" Grid.Row="1" Grid.Column="2" />

                <Label Content="lbl_Commentaires"   Height="25" Width="250"   Name="lbl_Commentaires" Margin="28,108,36,51" Grid.Row="1" Grid.ColumnSpan="2" />

            <Button Content="Commentaire"   Name="btn_Commentaires"   Width="106px" Height="25" Margin="11,56,287,104" Grid.Row="1" Grid.Column="2" />
            <Label Content="Causes Arret" VerticalContentAlignment="Bottom"   HorizontalAlignment="Left" Margin="55,0,0,-2" Name="lbl_TitleArret"  Width="184" Grid.RowSpan="2" Grid.Column="1" Grid.ColumnSpan="2" />
            <Label Content="Categories" Width="200"  Height="25"    Name="lbl_Title_Cat" Margin="6,156,39,4" Grid.Row="1" />
            <Button Content="..." Height="23" HorizontalAlignment="Left" Margin="38,29,0,0" Name="btn_ClavDuree" VerticalAlignment="Top" Width="41" Grid.Row="1" Grid.Column="1" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="155,23,0,0" Name="txt_ArretManuel_Duree" VerticalAlignment="Top" Width="107" Grid.Column="1" Grid.ColumnSpan="2" />
            <TextBlock Text="Durée (en minutes):"    Foreground="Black"  Name="lbl_Duree" FontWeight="SemiBold"  Background="#FFDB1111"   Grid.Row="0"  Grid.Column="1" />
           <TextBox Height="23" HorizontalAlignment="Left" Margin="96,21,0,0" Name="txt_ArretManuel_Fin" VerticalAlignment="Top" Width="98" Grid.Column="2" />
                <Label Content="Veuillez créer l'arrêt manuel " Height="28" HorizontalAlignment="Left" Margin="6,133,0,0" Name="lbl_Alerte" VerticalAlignment="Top" Width="165" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
            </Grid>

        <!-- Grid des 3 boutons Supp arret /effa / Annuler -->
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
                <RowDefinition Height="1*" />
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>
            <Button Content="Supprimer arrêt" FontWeight="Bold"  FontSize="16" Foreground="DarkBlue" Margin="2,4,2,2" Name="btn_Delete"/>
            <Button Content="Effacer justification" FontWeight="Bold"  FontSize="16" Foreground="DarkBlue"  Margin="2" Name="btn_Reset"  Grid.Row="1" />
            <Button Content="Annuler" FontWeight="Bold"  FontSize="16" Foreground="DarkBlue" Margin="2,2,2,4" Name="btn_Annuler" Grid.Row="2" />
        </Grid>

        <!-- Ce grid est un host pour le datagrid des arrets selectionnées -->
        <Grid Visibility="Hidden"    Grid.Column="0" >
            <WindowsFormsHost  Padding="20" Name="windowsFormsHost1" >
                <wf:DataGridView  x:Name="gv_ArretProd" Dock="Fill"></wf:DataGridView>
            </WindowsFormsHost>
        </Grid>

          </Grid>
    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100*" />
            <ColumnDefinition Width="798*" />
        </Grid.ColumnDefinitions>
        <TabControl   Name="tab_causes" TabStripPlacement="Left" Grid.ColumnSpan="2">

        </TabControl>
        <!--<Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="8*" />
        </Grid.ColumnDefinitions>
        <Grid Background="Beige"   Name="grd"  >
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>


            </Grid.RowDefinitions>
            <Button  Grid.Row="0" Content="Button5" Margin="5"    />
            <Button Grid.Row="1"   Margin="5">
                <Viewbox> <TextBlock> Qualité composant-PCB/consommable</TextBlock> </Viewbox>
            </Button>
            <Button  Grid.Row="2"  Margin="5">  <Viewbox> <TextBlock> Qualité composant-PCB/consommable</TextBlock> </Viewbox> </Button>
            <Border Background="#FFD7E5F5" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5,0.5,0,0.5">
            <Button     Margin="5">  <Viewbox> <TextBlock> Qualité composant-PCB/consommable</TextBlock> </Viewbox> </Button>
           </Border> <Button Grid.Row="4"   Margin="5">  <Viewbox> <TextBlock> Qualité composant-PCB/consommable</TextBlock> </Viewbox> </Button>
            <Border Background="#FFD7E5F5" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5,0.5,0,0.5">
                <Button     Margin="5">
                    <Viewbox>
                        <TextBlock > Qualité composant-PCB/consommable</TextBlock>
                    </Viewbox>
                </Button>
            </Border>
            <Button Grid.Row="4"   Margin="5">
                <Viewbox>
                    <TextBlock> consommable</TextBlock>
                </Viewbox>
            </Button> 
      </Grid>
        <WrapPanel Grid.Column="1"  Margin="0,0,5,0" Name="wrapPanel1" Background="#FFD7E5F5"/>-->
    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:0)

这是造成问题的代码。

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="1*" />
    <ColumnDefinition Width="1*" />
    <ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition Height="1*" />
    <RowDefinition Height="4*" />

您将按钮放在行= 0,列= 0中。由于您将列按1:1:3的比例划分,因此它只占空间的20%,这对于按钮内容来说太小了显示得当。因此,请根据您的要求正确更改色谱柱宽度除以2:1:2的比例。