为什么我的按钮在XAML设计器中不可见?

时间:2015-02-11 05:37:55

标签: wpf xaml

我有以下死标准(没有有趣的包含或任何内容):

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="50" />
        <RowDefinition Height="6" />
        <RowDefinition Height="94"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" VerticalAlignment="Center" Margin="0,5" >
        <DockPanel LastChildFill="True" Margin="0,5" VerticalAlignment="Center">
            <Label Margin="2" Content="Last Message:"/>
            <TextBox IsReadOnly="True" Text="{Binding SchedulerStatus, Mode=OneWay}" DockPanel.Dock="Left" Height="30" VerticalContentAlignment="Center" Margin="0, 0, 10, 0" />
        </DockPanel>
    </Grid>
    <StackPanel Grid.Row="1"></StackPanel>
    <StackPanel x:Name="ButtonPanel" Grid.Row="2" Orientation="Horizontal" Height="100" HorizontalAlignment="Stretch" Tag="Command" >
        <Button x:Name="Start" IsEnabled="True" Command="{Binding StartCommand}" Content="Start Service" Height="50" Margin="20, 10, 10, 10" Width="95" Tag="Command" />
        <Button x:Name="Pause"  IsEnabled="True" Content="Pause Service" Height="50" Margin="10" Width="95" Tag="Command" />
        <Button x:Name="Stop" IsEnabled="True" Command="{Binding StopCommand}" Content="Stop Service" Height="50" Margin="10" Width="95" Tag="Command"  />
        <Button x:Name="Process" IsEnabled="True" Content="Force Processing" Height="50" Margin="10" Width="95" Tag="Command"  />
        <Button x:Name="Config" IsEnabled="True" Content="Configuration" Height="50" Margin="10" Width="95" Tag="Command"  />
    </StackPanel>
</Grid>

然而,没有任何按钮可见。如果我制作Grid.Row="1",我可以看到半按钮轮廓,因为第1行不如第2行高。如果我将鼠标悬停在按钮行上,我可以在我悬停时看到每个按钮的轮廓,但是在ops normal下,所有按钮都是不可见的。这些按钮在运行时也是不可见的。

2 个答案:

答案 0 :(得分:1)

我在rowdefinitions中做了一些修改,检查

<Window x:Class="Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" VerticalAlignment="Center" Margin="0,5" >
            <DockPanel LastChildFill="True" Margin="0,5" VerticalAlignment="Center">
                <Label Margin="2" Content="Last Message:"/>
                <TextBox IsReadOnly="True" Text="{Binding SchedulerStatus, Mode=OneWay}" DockPanel.Dock="Left" Height="30" VerticalContentAlignment="Center" Margin="0, 0, 10, 0" />
            </DockPanel>
        </Grid>
        <StackPanel Grid.Row="1"></StackPanel>
        <StackPanel x:Name="ButtonPanel" Grid.Row="2" Orientation="Horizontal" Height="100" HorizontalAlignment="Stretch" Tag="Command" >
            <Button x:Name="Start" IsEnabled="True" Command="{Binding StartCommand}" Content="Start Service" Height="50" Margin="20, 10, 10, 10" Width="95" Tag="Command" />
            <Button x:Name="Pause"  IsEnabled="True" Content="Pause Service" Height="50" Margin="10" Width="95" Tag="Command" />
            <Button x:Name="Stop" IsEnabled="True" Command="{Binding StopCommand}" Content="Stop Service" Height="50" Margin="10" Width="95" Tag="Command"  />
            <Button x:Name="Process" IsEnabled="True" Content="Force Processing" Height="50" Margin="10" Width="95" Tag="Command"  />
            <Button x:Name="Config" IsEnabled="True" Content="Configuration" Height="50" Margin="10" Width="95" Tag="Command"  />
        </StackPanel>
    </Grid>
</Window>

答案 1 :(得分:0)

从ButtonPanel中移除高度和宽度。然后按钮可见。 代码是: -

<Window x:Class="Demo_wpf.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="600" Width="600">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="50" />
        <RowDefinition Height="100" />
        <RowDefinition Height="94"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" VerticalAlignment="Center" Margin="0,5" >
        <DockPanel LastChildFill="True" Margin="0,5" VerticalAlignment="Center">
            <Label Margin="2" Content="Last Message:"/>
            <TextBox IsReadOnly="True" Text="{Binding SchedulerStatus, Mode=OneWay}" DockPanel.Dock="Left" Height="30" VerticalContentAlignment="Center" Margin="0, 0, 10, 0" />
        </DockPanel>
    </Grid>
    <StackPanel Grid.Row="1"></StackPanel>
    <StackPanel x:Name="ButtonPanel" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Stretch" Tag="Command" >
        <Button x:Name="Start" IsEnabled="True" Command="{Binding StartCommand}" Content="Start Service" Height="50" Margin="20, 10, 10, 10" Width="95" Tag="Command" />
        <Button x:Name="Pause"  IsEnabled="True" Content="Pause Service" Height="50" Margin="10" Width="95" Tag="Command" />
        <Button x:Name="Stop" IsEnabled="True" Command="{Binding StopCommand}" Content="Stop Service" Height="50" Margin="10" Width="95" Tag="Command"  />
        <Button x:Name="Process" IsEnabled="True" Content="Force Processing" Height="50" Margin="10" Width="95" Tag="Command"  />
        <Button x:Name="Config" IsEnabled="True" Content="Configuration" Height="50" Margin="10" Width="95" Tag="Command"  />
    </StackPanel>
</Grid>