【问题标题】:how to add hyperlink to stack panel in xaml如何在xaml中将超链接添加到堆栈面板
【发布时间】:2014-05-27 07:00:31
【问题描述】:

我使用 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>

如何将超链接添加到整个堆栈面板并且我的超链接值在数据绑定中

【问题讨论】:

  • 您想为 StackPanel 或 TextBlock 添加?你的问题标题是 TextBlock
  • 将所需的 StackPanel 或 TextBlock 包裹在“HyperlinkBut​​ton.Content”中
  • @sanjeetharan:对不起,我只需要编辑堆栈面板...
  • @bit 标签在环绕堆栈面板时不被接受
  • 在我的回答中查看示例

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


【解决方案1】:

这是一个例子

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

【讨论】:

  • 添加后我所有的列表值都被隐藏了
【解决方案2】:

HyperLinkButton 仅支持文本。

<HyperlinkButton>
    Hello World
</HyperlinkButton>

但是你可以这样做,设置一个Control模板,然后在里面输入你上面提到的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>

【讨论】:

  • x:key 不可用
  • @user2992174 好的检查修改后的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-06
相关资源
最近更新 更多