如何在xaml中添加超链接到堆栈面板

时间:2014-05-27 07:00:32

标签: c# xaml windows-phone-8 windows-phone-8.1

我使用c#从Web服务中获取了绑定值,我的xaml代码如下所示

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel>
    <ListBox x:Name="PhoneList" Height="532" Background="{x:Null}">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <StackPanel Orientation="Horizontal">
   <Image Height="100" Margin="5" Stretch="Fill" Width="100"  Source="{Binding blogImage}"></Image>
     <Grid x:Name="ContentPanel" Margin="20,0,0,0"  Width="300" >
      <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>

    </Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" LineHeight=" 24" MaxHeight=" 48"LineStackingStrategy="BlockLineHeight" Grid.Row="0" Foreground="Black" FontStyle="Normal" Text="{Binding blogTitle }" Margin="0,0,0,0"/>
 <TextBlock Grid.Row="2" VerticalAlignment="Top" TextWrapping="Wrap"  Margin="0,3,0,0" Foreground="BlueViolet" FontStyle="Italic" Text="{Binding blogPostedon }" />

      </Grid>
        </StackPanel>
</DataTemplate>
  </ListBox.ItemTemplate>
    </ListBox>
  </StackPanel>
   </Grid>

如何将超链接添加到整个堆栈面板,我的超链接值是数据绑定

2 个答案:

答案 0 :(得分:0)

这是一个例子

<HyperLinkButton>
    <HyperLinkButton.Content>
        <StackPanel>
            ...
        </StackPanel>
    </HyperLinkButton.Content>
</HyperLinkButton>

答案 1 :(得分:0)

HyperLinkButton仅支持文字。

<HyperlinkButton>
    Hello World
</HyperlinkButton>

但你可以这样做,设置一个控制模板并输入上面提到的XAML

  <HyperlinkButton>
    <HyperlinkButton.Template>
    <ControlTemplate x:Key="MyTemplate" TargetType="Button">
        <StackPanel>
        <ListBox x:Name="PhoneList" Height="532" Background="{x:Null}">
        <ListBox.ItemTemplate>
        <DataTemplate>
        <StackPanel Orientation="Horizontal">
            .....
        </StackPanel>
        </DataTemplate>
        </ListBox.ItemTemplate>
        </ListBox>
      </StackPanel>
    </ControlTemplate>
  </HyperlinkButton.Template>
</HyperlinkButton>