C# 在wpf中工作时隐藏标签和按钮

C# 在wpf中工作时隐藏标签和按钮,c#,wpf,visual-studio,C#,Wpf,Visual Studio,我想在WPF C#(使用Visual Studio)中使用代码时隐藏标签和按钮 有什么方法可以做到这一点吗?您可以在这些元素上添加属性d:ishiden=“true” 见: 如果尚未存在,则添加xmlns:d=”http://schemas.microsoft.com/expression/blend/2008" 在只想在设计时隐藏的元素上放置d:ishiden=“true” Aspx页面: ___________ 输入名称: 下面是使标签在单击按钮时可见的代码。 __________

我想在WPF C#(使用Visual Studio)中使用代码时隐藏标签和按钮
有什么方法可以做到这一点吗?您可以在这些元素上添加属性
d:ishiden=“true”

见:

  • 如果尚未存在,则添加xmlns:d=”http://schemas.microsoft.com/expression/blend/2008"
  • 在只想在设计时隐藏的元素上放置d:ishiden=“true”
Aspx页面:
___________
输入名称:



下面是使标签在单击按钮时可见的代码。 _________________________________________________________ 受保护的无效提交(对象发送者、事件参数e) { lblMessage.Visible=true; RegisterStartupScript(this.GetType(),“alert”,“HideLabel();”,true); } 使用JavaScript在5秒后自动隐藏标签控件 ___________________________________________________________________ 下面是JavaScript函数,它将在5秒后隐藏标签。单击按钮时,使用ClientScript RegisterStartupScript方法调用此函数。 变量seconds保存该值,该值确定标签将在多少秒后隐藏。您可以根据需要在几秒钟内设置所需的任何值。 最后,在JavaScript setTimeout函数中,通过将标签的CSS display属性设置为none来隐藏标签,并通过将“seconds”变量乘以1000来指定超时,因为setTimeout函数接受以毫秒为单位的值。 函数HideLabel(){ var秒=5; setTimeout(函数(){ document.getElementById(“”.style.display=“无”; },秒*1000); };
您想将它们隐藏在Visual Studio或Visual Studio中的应用程序中,以便我可以在其下方的C#代码中放置另一页,以便进一步澄清这一点。您的设计器中已有一些按钮和标签,您需要在其下方放置一个元素,当前,当您尝试这样做时,您的按钮和标签最终会被该元素覆盖。这是正确的吗?我想创建一个菜单,当你点击一个按钮时,所有的东西都消失了,下面的元素都是可见的。
Aspx page:
___________
Enter Name:
<asp:TextBox ID="txtName" runat="server" />
<br />
<asp:Button Text="Submit" runat="server" OnClick="Submit" /><br />
<br />
<asp:Label ID="lblMessage" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully." runat="server" Visible="false" />

Below is the code to make the Label visible on button click.
_________________________________________________________
protected void Submit(object sender, EventArgs e)
{
    lblMessage.Visible = true;
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabel();", true);
}

Automatically Hiding Label control after 5 seconds using JavaScript
___________________________________________________________________
Below is the JavaScript function that will hide the Label after 5 seconds. This function gets called using ClientScript RegisterStartupScript method when the Button is clicked.
A variable seconds holds the value which determines after how many seconds the Label will hide. You can set whatever value you need in seconds as per your requirement.
Finally within JavaScript setTimeout function, the Label is hidden by setting its CSS display property to none and the timeout is specified by multiplying the ‘seconds’ variable to 1000 as setTimeout function accepts value in Milliseconds.

<script type="text/javascript">
    function HideLabel() {
        var seconds = 5;
        setTimeout(function () {
            document.getElementById("<%=lblMessage.ClientID %>").style.display = "none";
        }, seconds * 1000);
    };
</script>