2013-08-30 4 views
0

하이퍼 링크 버튼이 있습니다. 제가 클릭 할 때, 인터넷 브라우저가 시작되면서 인터넷 브라우저가 시작됩니다.클릭 후 하이퍼 링크 버튼 이벤트 취소

일부 조건에서이 HyperlinkButton 이벤트를 취소하고 싶습니다. 예를 들어

: 인터넷 브라우저를 실행하지 않는 인터넷에 연결, 응용 프로그램에 숙박이없는 경우 hyperlinkbutton에

  • 사용자가 클릭은
  • 응용 프로그램은 인터넷 연결
  • 을 확인

예제 코드 (이와 비슷한 코드) :

<Page x:Class="App1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> 
<Grid> 
    <HyperlinkButton NavigateUri="http://stackoverflow.com/" Content="GO TO WEBPAGE" Click="HyperlinkButton_Click_1" /> 
</Grid> 
</Page> 

private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e) 
{ 
    var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); 
    if (connectionProfile == null || connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.LocalAccess || connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.None) 
    { 
     NO INTERNET, CANCEL THE EVENT!!!!!!!! 
    } 
} 

그렇다면 어떻게 클릭하면 HyperlinkButton 이벤트를 취소 할 수 있습니까?

답변

1

return 키워드를 사용할 수 있습니다.

MSDN

The return statement terminates execution of the method in which it 
appears and returns control to the calling method. 
It can also return the value of the optional expression. 
If the method is of the type void, the return statement can be omitted. 

Further Reference

+0

+1 참고 용으로. – Jonast92

0

당신은 return 문을 사용할 수 있습니다. 이다

return; 

,

if (condition) 
{ 
    return; 
} 
0

당신은 잘못된 방법으로 if을 사용하고 있습니다. 너는 이렇게해야한다.

private async void HyperlinkButton_Click_1(object sender, RoutedEventArgs e) 
{ 
    var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); 
    if (connectionProfile != null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess) 
    { 
     //TODO: open link 
    } 
    else 
    { 
     await new Windows.UI.Popups.MessageDialog("Internet is not available.").ShowAsync(); 
    } 
}