2015-11-12 20 views
1

我是WPF的新手,並且已經編寫了一個簡單的Hello World類型應用程序以便開始使用。我到目前爲止的代碼如下所示:WPF窗口 - 其他控件在添加超鏈接控件後無法響應點擊

WPF XAXML

<Window x:Name="wndMain" x:Class="MyApp.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ews="clr-namespace:ExtraWindowStyles" 
     ResizeMode="NoResize" 
     ews:ExtraWindowStyles.CanMinimize="false" 
     ews:ExtraWindowStyles.CanMaximize="false"   
     Title="Hello World" Height="501.492" Width="842.285"> 
    <Grid> 
     <GroupBox Header="Input Parameters" HorizontalAlignment="Left" Height="173" Margin="10,25,0,0" VerticalAlignment="Top" Width="801" > 
      <StackPanel Orientation="Horizontal" Margin="0,0,96,0"> 
       <StackPanel Margin="10"> 
        <Label FontWeight="Bold">First Group</Label> 
        <RadioButton x:Name="opt11">Option 1 - 1</RadioButton> 
        <RadioButton x:Name="opt12">Option 1 - 2</RadioButton> 
        <RadioButton x:Name="opt13">Option 1 - 3</RadioButton> 
       </StackPanel> 
       <StackPanel Margin="10"> 
        <Label FontWeight="Bold" Content="Second Group"/> 
        <RadioButton x:Name="opt21" Content="Option 2 - 1"/> 
        <RadioButton x:Name="opt22" Content="Option 2 - 2"/> 
        <RadioButton x:Name="opt23" Content="Option 2 - 3"/> 
       </StackPanel> 
      </StackPanel> 

     </GroupBox> 
     <Separator HorizontalAlignment="Left" Height="80" Margin="17,203,0,0" VerticalAlignment="Top" Width="794"/> 
     <Button x:Name="btnSubmit" Content="Submit" HorizontalAlignment="Left" Height="34" Margin="632,203,0,0" VerticalAlignment="Top" Width="179" Click="btnExplore_Click" /> 
     <Label Content="Results:" HorizontalAlignment="Left" Height="28" Margin="10,242,0,0" VerticalAlignment="Top" Width="161"/> 
     <Label Content="My App" HorizontalAlignment="Left" Height="23" Margin="696,439,0,0" VerticalAlignment="Top" Width="130" FontSize="9"/> 
     <TextBlock>   
      <Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate"> 
       Click Here 
      </Hyperlink> 
     </TextBlock> 
     <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="162" Margin="17,270,0,0" Stroke="Black" VerticalAlignment="Top" Width="794"/> 
     <Label x:Name="lblResult" Content="" HorizontalAlignment="Left" Height="157" Margin="17,275,0,0" VerticalAlignment="Top" Width="794"/> 
    </Grid> 
</Window> 

代碼隱藏..

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) 
{ 
    Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); 
    e.Handled = true; 
} 

如果我註釋掉的超鏈接控制XAML(及其相關後端代碼),我可以選擇選項,單擊提交按鈕等。

Howeve r,如果我取消註釋超鏈接控件(及其關聯的後端代碼),唯一可以點擊的是表單上的Url - 發生了什麼?

+0

您是否有任何爲「超鏈接」定義的樣式? – Domysee

回答

2

公正立場您TextBlock,它不會採取一切空間,在窗口和麪面俱到:

<TextBlock Width="100" Height="30"> 
    <Hyperlink Background="Red" NavigateUri="http://www.google.com" > 
     Click Here 
    </Hyperlink> 
</TextBlock> 

因爲TextBlock被提交在XAML後按鈕,它已經結束了。 您還可以設置保證金來定位TextBlock

佈局知識網格拉伸平鋪
元素和垂直方向上,如果沒有對齊設置。

有用的提示:如果你點擊TextBlock標籤,你會看到TextBlock的程度在設計視圖。
通常很有用