gpt4 book ai didi

c# - 如何更改DataGrid中超链接的字体颜色

转载 作者:行者123 更新时间:2023-11-30 22:01:30 24 4
gpt4 key购买 nike

如何在 WPF (C#) 的 DataGrid 中更改超链接链接(字体)的颜色?

现在,我的超链接列是这样呈现的:(XAML)

<DataGridHyperlinkColumn Width="300" Binding="{Binding link}" ContentBinding="{Binding link}" 
Header="Link" HeaderStringFormat="Link">
<DataGridHyperlinkColumn.ElementStyle>
<Style>
<EventSetter Event="Hyperlink.Click" Handler="DG_Hyperlink_Click"/>
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>

最佳答案

试试这个

xaml

 <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridHyperlinkColumn Header="Email" Binding="{Binding Email}">
<DataGridHyperlinkColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Style.Resources>
<Style TargetType="Hyperlink">
<Setter Property="Foreground" Value="Chocolate"></Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Hyperlink.Click">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Foreground.Color" From="Chocolate" To="BlueViolet" Duration="0:0:0.1"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Style.Resources>
</Style>
</DataGridHyperlinkColumn.CellStyle>
</DataGridHyperlinkColumn>
</DataGrid.Columns>
</DataGrid>

c#代码

   public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
ObservableCollection<Customer> custdata = new ObservableCollection<Customer>();
custdata.Add(new Customer() { Email = new Uri("http://stackoverflow.com/") });
DG1.ItemsSource = custdata;
}
}
public class Customer
{
public Uri Email { get; set; }
}

结果

enter image description here

enter image description here

关于c# - 如何更改DataGrid中超链接的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27648226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com