简体   繁体   English

为什么我什么都看不到?

[英]Why can't I see anything?

Just tried a GUI code and at first I could see text, buttons after first compile.刚刚尝试了一个 GUI 代码,起初我可以在第一次编译后看到文本和按钮。 Then I tried to hook up the buttons to the RadioButton, after compiling this all I was able to see was plain white.然后我尝试将按钮连接到 RadioButton,编译后我只能看到纯白色。

The .xaml code: .xaml 代码:

<Window x:Class="GUItest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GUItest"
        mc:Ignorable="d"
        Title="MainWindow" Height="855" Width="1628">
    <Grid RenderTransformOrigin="0.500,0.525" Margin="0,0,0,-6">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0*"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Grid>
            <TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="76"/>
        </Grid>

        <Grid>
            <TextBlock HorizontalAlignment="Left" Margin="10,305,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Height="150" Width="237" RenderTransformOrigin="0.476,0.498"/>
            <RadioButton x:Name="ABC" Content="ABC" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
            <RadioButton x:Name="DEF" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
        </Grid>

        <Grid>
            <RadioButton x:Name="ABCButton" Content="ABC" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
            <RadioButton x:Name="DEFButton" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
            <TextBlock HorizontalAlignment="Left" Margin="0,0,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="238" Height="143" RenderTransformOrigin="0.50-53,0.501">
                <TextBlock.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform AngleX="-0.1"/>
                        <RotateTransform/>
                        <TranslateTransform X="-0.332"/>
                    </TransformGroup>
                </TextBlock.RenderTransform>
            </TextBlock>
        </Grid>

    </Grid>
</Window>

And this is the .xaml.cs code:这是 .xaml.cs 代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GUItest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (ABCButton.IsChecked == true)
            {
                MessageBox.Show("ABC");
            }
            else if (DEFButton.IsChecked == true)
            {
                MessageBox.Show("DEF");
            }
        }
    }
}

This is just made by me to better understand the GUI.这只是我为了更好地理解 GUI 而制作的。

All of your items fall in the first column and your ColumnWidth of the first one is 0*.您的所有项目都位于第一列中,并且您的第一列的 ColumnWidth 为 0*。 This means that the width will be 0 (times) x, which results in a width of 0.这意味着宽度将为 0(倍)x,从而导致宽度为 0。

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

Try to make this * or 2* or something, or place the items in a different column.尝试制作此 * 或 2* 或其他内容,或将项目放在不同的列中。 Good luck.祝你好运。

Edit:编辑:

Placing the items in a different column can be done by:可以通过以下方式将项目放在不同的列中:

    <Grid Grid.Column="1">
        <TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="76"/>
    </Grid>

    <Grid Grid.Column="1"> <!-- Here the 1 means place this grid in the first column of the main grid -->
        <TextBlock HorizontalAlignment="Left" Margin="10,305,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Height="150" Width="237" RenderTransformOrigin="0.476,0.498"/>
        <RadioButton x:Name="ABC" Content="ABC" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
        <RadioButton x:Name="DEF" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
    </Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM