I have a datagrid column that has Hyperlinkbuttons. You have to click the button twice to have the button do what it’s supposed to do. I think the first click actually selects the row.
I believe something may be going on where the event doesn’t bubble up (or down?) to the hyperlink button.
Ideas?
edit
Here’s the xaml:
<sdk:DataGrid Grid.Row="1" x:Name="workflowsGrid" Margin="6,20,6,0" ItemsSource="{Binding FilteredSource,ElementName=workflowsFilter}"
AutoGenerateColumns="False" SelectedItem="{Binding SelectedWorkflow,Mode=TwoWay}"
SelectionChanged="workflowsGrid_SelectionChanged">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Name" Binding="{Binding Description}"/>
<sdk:DataGridTemplateColumn Header="Action" >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ContentControl Content="{Binding Converter={StaticResource actionConverter}}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
And here’s the converter that adds the hyperlink buttons:
/// <summary>
/// Dynamically controls the action cell in the workflows grid
/// </summary>
protected class ActionValueConverter : IValueConverter
{
private WorkflowManager _page;
public ActionValueConverter(WorkflowManager page)
{
_page = page;
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var workflow = (WorkflowInstance)value;
if (workflow.Status == "Complete")
{
// create hyperlink buttons for each action that the workflow supports
var btns = workflow.Definition.Actions
.Select(x =>
{
HyperlinkButton btn = new HyperlinkButton
{
Tag = Tuple.Create(workflow, x.Key),
Content = x.Value,
};
btn.Click += new RoutedEventHandler(_page.ActionButton_Click);
return btn;
});
// stack panel to contain all the buttons
StackPanel sp = new StackPanel { Orientation = Orientation.Vertical };
foreach (var btn in btns)
sp.Children.Add(btn);
return sp;
}
else if (workflow.Status == "In Progress")
{
// create only a cancel hyperlink button
HyperlinkButton btnCancel = new HyperlinkButton { Content = "Cancel", Tag = Tuple.Create(workflow, "Cancel") };
btnCancel.Click += new RoutedEventHandler(_page.ActionButton_Click);
return btnCancel;
}
else
{
throw new Exception("workflow status not supported: " + workflow.Status);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
May be you should use the Edit template instead of the Cell template as specified in the following link:
http://forums.silverlight.net/p/132619/296134.aspx
That ways your link column will always be in Edit mode and should require only a single click.
Edit:
instead of
Hope it helps!