Reputation: 85996
I have a WPF form with a DataGrid
containing multiple DataGridHyperlinkColumn
, with a Hyperlink.click
handler set up.
GamesGrid.xaml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SteamWishlist"
x:Name="gamesGridControl" x:Class="MyProgram.GamesGrid"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DataGrid x:Name="dataGrid" AutoGenerateColumns="False" CanUserSortColumns="False" SelectionUnit="Cell" SelectionMode="Single" AreRowDetailsFrozen="True" CanUserResizeRows="False" >
<DataGrid.Columns>
<DataGridHyperlinkColumn ClipboardContentBinding="{x:Null}" Binding="{Binding Url}" ContentBinding="{Binding Name}" Header="Name">
<DataGridHyperlinkColumn.ElementStyle>
<Style>
<EventSetter Event="Hyperlink.Click" Handler="DG_Hyperlink_Click"/>
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
<DataGridHyperlinkColumn ClipboardContentBinding="{x:Null}" Binding="{Binding InstallLink}" Header="Install">
<DataGridHyperlinkColumn.ElementStyle>
<Style>
<EventSetter Event="Hyperlink.Click" Handler="DG_Hyperlink_Click"/>
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>
GamesGrid.xaml.cs:
public partial class GamesGrid : UserControl
{
...
private void DG_Hyperlink_Click(object sender, RoutedEventArgs e)
{
Hyperlink link = (Hyperlink)e.OriginalSource;
Process.Start(link.NavigateUri.AbsoluteUri);
}
}
A few weeks ago this exact code worked just fine, but today the event is suddenly not being fired - if I set a breakpoint in DH_Hyperlink_Click
, it's never reached.
I'm not sure where to even start debugging this issue. Has anyone else encountered this before?
Upvotes: 1
Views: 1265
Reputation: 85996
Of course, the problem turned out to be yet another completely random WPF bug, sigh.
Apparently if you set DataGrid.ItemSource
after an await
inside a TextBox.LostKeyboardFocus
callback, it breaks the DataGridHyperlinkColumn.Hyperlink.Click
event. Why? I have no idea.
I tried everything I could think of to work around the issue, but nothing worked. In the end I had to stop using await
inside the callback and handle asynchronous events manually. Sigh.
Upvotes: 1