2017-02-23 98 views
0

工作時我想隱藏標籤和按鈕與我的WPF的C#代碼的工作(使用Visual Studio) 而有什麼辦法,我可以做到這一點隱藏標籤和按鈕在WPF

+0

你想隱藏在Visual Studio或在應用程序? –

+0

在Visual Studio中,我可以在其下面放置另一個頁面 –

+0

在C#代碼中? –

回答

1

您可以添加屬性d:IsHidden="true"在這些元素上。

this post

  • 如果添加不存在的xmlns:d = 「http://schemas.microsoft.com/expression/blend/2008」
  • 放d:是否隱藏=」真正的」元素上要隱藏在設計時只
0
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>