Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight HyperlinkButton in DataGrid column. Have to click twice
    text
    copied!<p>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.</p> <p>I believe something may be going on where the event doesn't bubble up (or down?) to the hyperlink button. </p> <p>Ideas?</p> <h1>edit</h1> <p>Here's the xaml:</p> <pre><code> &lt;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"&gt; &lt;sdk:DataGrid.Columns&gt; &lt;sdk:DataGridTextColumn Header="Name" Binding="{Binding Description}"/&gt; &lt;sdk:DataGridTemplateColumn Header="Action" &gt; &lt;sdk:DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ContentControl Content="{Binding Converter={StaticResource actionConverter}}"/&gt; &lt;/DataTemplate&gt; &lt;/sdk:DataGridTemplateColumn.CellTemplate&gt; &lt;/sdk:DataGridTemplateColumn&gt; &lt;/sdk:DataGrid.Columns&gt; &lt;/sdk:DataGrid&gt; </code></pre> <p>And here's the converter that adds the hyperlink buttons:</p> <pre><code>/// &lt;summary&gt; /// Dynamically controls the action cell in the workflows grid /// &lt;/summary&gt; 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 =&gt; { 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(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload