Note that there are some explanatory texts on larger screens.

plurals
  1. POClick Event not fired in WPF Datagrid in unselected row
    primarykey
    data
    text
    <p>I have a DataGrid (WPF 4) like this:</p> <pre><code>&lt;DataGrid Margin="0,0,0,5" VerticalAlignment="Top" Height="192" BorderBrush="#aaa" Background="White" HorizontalAlignment="Left" ItemsSource="{Binding Namen, Mode=OneWay}" ScrollViewer.VerticalScrollBarVisibility="Visible" AutoGenerateColumns="False" ColumnHeaderHeight="24" SelectionChanged="DataGridAuslaendischeAlteNamen_SelectionChanged"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Width="*" Header="Namenseintrag" Binding="{Binding DisplayName, Mode=OneWay}" /&gt; &lt;DataGridTextColumn Width="75" Header="gültig von" Binding="{Binding GueltigAb, StringFormat=d, Mode=OneWay}" /&gt; &lt;DataGridTextColumn Width="75" Header="gültig bis" Binding="{Binding GueltigBis, StringFormat=d., Mode=OneWay}" /&gt; &lt;DataGridTemplateColumn Width="20" IsReadOnly="True"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Button Style="{DynamicResource CaratRemoveButton}" Click="Button_Click" CommandParameter="{Binding}" PreviewMouseDown="Button_PreviewMouseDown" /&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; </code></pre> <p>The issue I experience is, that a button of the <code>DataGridTemplateColumn</code> does not fire the click-event, if its row is not selected. So I have to click a button twice, one time to select its row and then to raise the click event. I read about similiar problems with checkbox-columns, but there the suggestion was obviously to use a template column. I tested to use the PreviewMouseDown-Event of the button, which works, but is not what I want, since then the button does not follow its usual grpahical click behaviour.</p> <p>What am I missing here? How can I get that click event by just clicking once, regardless of whether the row was selected or not?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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