2015-12-08 97 views
0

我製作了一個簡單的按鈕 - 當您按下它時,圖像就會出現。 我做了image.Stretch = "Fill"所以我現在的問題是:wpf在顯示後關閉圖片

當圖像出現時,我該如何回來?如何在不停止程序的情況下再次關閉圖像。

我的button_click下代碼很簡單:

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

我想以某種方式使再次隱藏圖像..

這裏是我的XAML代碼

<Button Name="Button1" Content="1" Click="Button_Click" /> 

<Image Name="nr1" Visibility="Hidden" Source="(ImageSource etc.)" "  Stretch="Fill"/> 

謝謝!

+0

你能告訴我們你的xaml嗎? – tgpdyk

+0

@tgpdyk當然! :) –

+0

刪除圖像的標準是什麼?一段時間後? – Sinatr

回答

0

你可以做這樣的事情:

<Grid> 
    <Button Name="Button1" Content="1" Click="Button1_OnClick"/> 
    <Button Name="nr1" Visibility="Hidden" Click="Nr1_OnClick"> 
     <Button.Template> 
      <ControlTemplate> 
       <Image Source="YourImage" Stretch="Fill" /> 
      </ControlTemplate> 
     </Button.Template> 
    </Button> 
</Grid> 


private void Button1_OnClick(object sender, RoutedEventArgs e) 
    { 
     if (nr1.Visibility == Visibility.Visible) 
     { 
      nr1.Visibility = Visibility.Hidden; 
      Button1.Visibility = Visibility.Visible; 
     } 
     else 
     { 

      nr1.Visibility = Visibility.Visible; 
      Button1.Visibility = Visibility.Hidden; 
     } 
    } 

    private void Nr1_OnClick(object sender, RoutedEventArgs e) 
    { 
     if (Button1.Visibility == Visibility.Visible) 
     { 
      Button1.Visibility = Visibility.Hidden; 
      nr1.Visibility = Visibility.Visible; 
     } 
     else 
     { 
      nr1.Visibility = Visibility.Hidden; 
      Button1.Visibility = Visibility.Visible; 
     } 
    } 

我相信這是類似於Sinatr的建議。 我希望你明白。