gpt4 book ai didi

c# - 类似于自动回复的功能

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:36 24 4
gpt4 key购买 nike

您好,我需要一个 WPF 应用程序的功能类似于 asp.net 中的 autopostback 选项。发生的事情是我有一个带有由 xml 文件填充的组合框的表单。因此,一旦用户选择“其他”作为选项,他们就会看到一个文本框和一个按钮。那么我的代码有什么问题吗?我使用比较字符串方法来实现该功能,但似乎它不起作用。

        private void comboBox1_SelectedIndexChanged(System.Object sender, System.EventArgs e)

{
if (comboBox1.SelectedValue.ToString() == "Others")
{
BuilderemailTextBox.Visibility = Visibility.Visible;
BuilderupdateButton.Visibility= Visibility.Visible;
}
else
{
BuilderemailTextBox.Visibility = Visibility.Hidden;
BuilderupdateButton.Visibility = Visibility.Hidden;
}
}

我还尝试了以下方法,也对 SelectedIndex 进行了更改。

        private void comboBox1_SelectedIndexChanged(System.Object sender, System.EventArgs e)

{
if (comboBox1.SelectedIndex.ToString() == "Others")
{
BuilderemailTextBox.Visibility = Visibility.Visible;
BuilderupdateButton.Visibility= Visibility.Visible;
}
else
{
BuilderemailTextBox.Visibility = Visibility.Hidden;
BuilderupdateButton.Visibility = Visibility.Hidden;
}
}

编辑 1:我的 XAML 文件:

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="309" Width="672">
<Grid>
<Button Height="23" Name="BuildButton" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="75" Click="BuildButton_Click">Build</Button>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="12,63,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox1_SelectedIndexChanged" />
<CheckBox Height="16" HorizontalAlignment="Left" Margin="66,0,0,140" Name="ExecbuildstartingmailCheckBox" VerticalAlignment="Bottom" Width="153">Exec Build Starting Mail</CheckBox>
<ComboBox Height="23" Margin="0,63,173,0" Name="comboBox2" VerticalAlignment="Top" HorizontalAlignment="Right" Width="120" />
<Button Height="23" Margin="270,63,0,0" Name="BuilderupdateButton" VerticalAlignment="Top" HorizontalAlignment="Left" Width="51" Visibility="Hidden">Button</Button>
<Button Height="23" Margin="0,63,73,0" Name="button2" VerticalAlignment="Top" HorizontalAlignment="Right" Width="74">Button</Button>
<TextBox Height="23" HorizontalAlignment="Left" Margin="144,63,0,0" Name="BuilderemailTextBox" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
</Grid>
</Window>

edit2 我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<email>
<builderemail>
<builder>
<value>builder@example.com</value>
</builder>
<builder>
<value>Others</value>
</builder>
</builderemail>
<manageremail>
<manager>
<value>manager@example.com</value>
</manager>
<manager>
<value>Others</value>
</manager>
</manageremail>
</email>

最佳答案

根据您的 XML,您可以获取 SelectedItem,转换它并访问它的属性。如果您的项目有一个名为 valueXmlElement,您想测试它的“Other”,您可以试试这个:

(comboBox1.SelectedItem as XmlElement).GetElementsByTagName("value")[0].InnerText == "Other"

关于c# - 类似于自动回复的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4967717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com