wpf 是否可以检查RadioButton并在运行时代码中将该项从隐藏变为可见?

pkln4tw6  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(135)

XAML

<Window x:Name="Social_Club" x:Class="SocialClub.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:GameMenu"
        mc:Ignorable="d"
        MouseDown="Window_MouseDown"
        WindowStyle="None"
        AllowsTransparency="True"
        Background="Transparent"
        Title="Game Menu" Height="450" Width="800" Icon="faviconSC.png">
    <Border BorderBrush="Black" BorderThickness="2" CornerRadius="30">
        <Grid>
            <Border Background="#31313e" CornerRadius="30" Grid.ColumnSpan="3" Grid.RowSpan="2"/>
            <Grid Grid.Row="0" Grid.Column="0">
                <Border Margin="8,6,138,4">
                    <Border.Background>
                        <ImageBrush Stretch="Fill" ImageSource="faviconSC.png"/>
                    </Border.Background>
                </Border>
                <TextBlock Text="Social Club" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="22" Margin="0,24,-22,24" FontFamily="Arial Black" Width="160" FontWeight="Bold" Foreground="White"/>
            </Grid>
            <StackPanel Grid.Row="1" Grid.Column="0">
                <RadioButton 
                    x:Name="gta6_btn"
                    Content="Grand Theft Auto VI" 
                    Foreground="#fff"
                    Height="70"
                    FontSize="18"
                    FontWeight="ExtraBold"
                    Style="{StaticResource MenuButtonTheme}"
                    />

                <RadioButton 
                    x:Name="rdr2_btn"
                    Content="Red Dead Redemption 2" 
                    Foreground="#fff"
                    Height="70"
                    FontSize="16"
                    FontWeight="ExtraBold"
                    Style="{StaticResource MenuButtonTheme}"
                    />

                <RadioButton 
                    Content="Grand Theft Auto VI" 
                    Foreground="#fff"
                    Height="70"
                    FontSize="18"
                    FontWeight="ExtraBold"
                    Style="{StaticResource MenuButtonTheme}"
                    />

                <RadioButton 
                    Content="Grand Theft Auto VI" 
                    Foreground="#fff"
                    Height="70"
                    FontSize="18"
                    FontWeight="ExtraBold"
                    Style="{StaticResource MenuButtonTheme}"
                    />

                <RadioButton 
                    Content="Grand Theft Auto VI" 
                    Foreground="#fff"
                    Height="70"
                    FontSize="18"
                    FontWeight="ExtraBold"
                    Style="{StaticResource MenuButtonTheme}"/>
            </StackPanel>

            <Border x:Name="gta6" Visibility="Hidden" Grid.Column="1" Grid.Row="1">
                <Grid>
                    <TextBlock Text="Rockstar games" Foreground="#FF636363" Margin="10,10,464,337" FontSize="15"/>
                    <TextBlock HorizontalAlignment="Left" Margin="10,35,0,0" TextWrapping="Wrap" 
                       Text="Grand Theft Auto VI" Foreground="#FFF" VerticalAlignment="Top" 
                       Height="30" Width="199" FontWeight="Bold" FontSize="20"/>
                    <Border CornerRadius="10" Margin="227,10,10,171">
                        <Border.Background>
                            <ImageBrush Stretch="Fill" ImageSource="prewiew.png"/>
                        </Border.Background>
                    </Border>
                </Grid>
            </Border>
            <Border Visibility="Hidden" Grid.Column="1" Grid.Row="1"></Border>
            <Border Visibility="Hidden" Grid.Column="1" Grid.Row="1"></Border>
            <Border Visibility="Hidden" Grid.Column="1" Grid.Row="1"></Border>
            <Border Visibility="Hidden" Grid.Column="1" Grid.Row="1"></Border>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="208*"/>
                <ColumnDefinition Width="587*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="37*" />
                <RowDefinition Height="186*" />
            </Grid.RowDefinitions>
        </Grid>
    </Border>
</Window>

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 SocialClub
{
    public partial class MainWindow : Window
    {
        private void Application_Exit(object sender, MouseButtonEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
                this.DragMove();
        }
        public MainWindow()
        {
            InitializeComponent();
        }

        public void activeMenu()
        {
            if(gta6_btn.IsChecked == true)
            {
                gta6.Visibility = Visibility.Visible;
            }
        }
    }
}

我想做一个应用程序的类型启动器,我不要求在这个线程来帮助我与未来的代码,并帮助我只与这个问题。问题的本质是,我想让它当单选按钮边框被选中时,它从隐藏变为可见。我为我的英语道歉,我对C# wpf的理解很少,因为我刚刚开始。
我试着通过检查来做,但边框就是不做可见

5jdjgkvh

5jdjgkvh1#

通过添加事件处理程序解决了问题

private void gta6_btn_Checked(object sender, RoutedEventArgs e)
    {
        gta6.Visibility = Visibility.Visible;
    }

相关问题