【发布时间】:2021-01-19 16:51:25
【问题描述】:
我有一个从网络检索文章的程序,基本上需要将所有文章显示在一个列表中,其中包含具有文章 ID、标题、uri、视图等的自定义项目。 我想将文章标题和 uri 合并为一个超链接,以便我看到标题,路径将是 uri,听起来像一个简单的超链接,但是,当我点击时,而不是直接在浏览器中打开链接它,我只是想让它把链接复制到我的剪贴板,这么多,我无法弄清楚该怎么做,如果它只是一次,我可以很容易地从代码和处理程序中完成它,但是因为它在一个列表,我需要从 xaml 完全配置它。 这是代码,我将它拆分,以便您可以准确地看到listItem样式的超链接在哪里,如果您能想到一个方法,那就太棒了。
<Style x:Key="ArticleListboxItem" TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="{StaticResource DefaultFont}" />
<Setter Property="FontWeight" Value="Regular" />
<Setter Property="FontSize" Value="16" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Border" UseLayoutRounding="{TemplateBinding UseLayoutRounding}" Padding="3" Background="{TemplateBinding Background}" BorderThickness="0" SnapsToDevicePixels="true">
<Grid Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" UseLayoutRounding="{TemplateBinding UseLayoutRounding}" Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0"/> <!--Just a spacer-->>
<Label Name="lblArticleId" Grid.Column="1" Content="{Binding Path=ArticleID}" Foreground="White" HorizontalContentAlignment="Left" FontSize="14"/>
这是我需要帮助的部分,代码不正确,但更多是为了显示结构,而我没有任何失败的尝试干预(失败是指我没有关闭事件)
<Hyperlink Name="linkArticle" Grid.Column="2" Text="{Binding Path=ArticleTitle}" Link="{Binding Path=ArticleLink}"/>
和其余的listItem样式:
<Label Name="lblViews" Grid.Column="3" Content="{Binding Path=ArticleViews}" Foreground="White" HorizontalContentAlignment="Right" FontSize="14"/>
<Label Name="lblDate" Grid.Column="4" Content="{Binding Path=ArticleDate}" Foreground="White" HorizontalContentAlignment="Right" FontSize="14"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!--Some color modifications that are irrelevant, like change foreground when mouse is over-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
【问题讨论】:
标签: c# wpf xaml microsoft-metro