0

我正在尝试向 xaml 矩形添加超链接,但它不起作用。我尝试使用按钮添加超链接,它可以工作。如何为下面的代码添加一组矩形的超链接。

如何为以下代码提供超链接

<Rectangle Fill="Red" HorizontalAlignment="Left" Height="38" Margin="1038,74,0,0" Stroke="Black" VerticalAlignment="Top" Width="426"/>
            <TextBlock HorizontalAlignment="Left" Margin="1173,82,0,0" TextWrapping="Wrap" Text="Pending Sites " VerticalAlignment="Top" Height="24" Width="142" Foreground="#FFF7F6F1" FontSize="20" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
                <TextBlock.RenderTransform>
                    <CompositeTransform Rotation="-0.098"/>
                </TextBlock.RenderTransform>
            </TextBlock>

我尝试使用 Button 的代码运行良好

<Button Content="Click to go to desc page" Click="Button_Click_1" Margin="62,376,0,357"/>
 private void Button_Click_1(object sender, RoutedEventArgs e)
        {
           this.Frame.Navigate(typeof(dPlanner2x.MyPageDetails));
        }
4

1 回答 1

2

与其尝试将 aRectangle变成可点击的对象,不如将 a 应用于 a 会Style更好Button

Style下面给出了一个改变 a 外观的例子Button

<Style x:Key="btnCommand" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Name="rct" 
                        TextBlock.Foreground="White"
                        Background="DarkGray"
                        BorderBrush="DarkGray"
                        BorderThickness="1"
                        Cursor="Hand"
                        UseLayoutRounding="True"
                        SnapsToDevicePixels="True"
                        Margin="10"
                        Height="24"
                        MinWidth="75">
                    <ContentPresenter TextBlock.FontStyle="Segoe UI Semibold"
                                      TextBlock.FontSize="14"/>
                </Border>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="rct"
                                Property="TextBlock.Foreground" 
                                Value="DarkGray" />
                        <Setter TargetName="rct"
                                Property="Background" 
                                Value="LightGray" />
                        <Setter TargetName="rct"
                                Property="BorderBrush" 
                                Value="DarkGray" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="rct"
                                Property="TextBlock.Foreground" 
                                Value="DarkGray" />
                        <Setter TargetName="rct"
                                Property="Background" 
                                Value="White" />
                        <Setter TargetName="rct"
                                Property="BorderBrush" 
                                Value="LightGray" />
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

显然,您会想要看起来完全不同的东西,但Style可以轻松修改上面的模板以满足您的需求。

于 2013-09-11T18:40:54.227 回答