2014-06-26 33 views
0

我有一個Telerik RadGridView綁定到一個集合,我發送SelectedItem時單擊其中一個單元格中的超鏈接。它的工作原理,但我必須先點擊該行的其他地方來設置選定的項目。這是不理想的,我期待設置SelectedItem當鏈接,或任何事情,點擊。WPF超鏈接GridView的選定項目點擊

我已經看到了如何與IsSelectedListViewItem但沒有對Telerik的RadGridView或通用GridView做到這一點的ListView

這裏是我的鏈接:

<DataTemplate> 
    <TextBlock Padding="3,0"> 
     <Hyperlink CommandParameter="{Binding SelectedItem, 
      RelativeSource={RelativeSource FindAncestor, 
      AncestorType={x:Type telerik:RadGridView}}}" 
      Command="{Binding Path=DataContext.SomeCommand, 
      RelativeSource={RelativeSource FindAncestor, 
      AncestorType={x:Type telerik:RadGridView}}, Mode=OneWay}"> 
      Click here please 
     </Hyperlink> 
    </TextBlock> 
</DataTemplate> 

回答

1

我認爲你需要設置UIElement.IsKeyboardFocusWithin property。我有這兩個Style s,我用來點擊一個孩子控制得到反映在ListBoxItem ...你可以只是將ListBoxItem更改爲ListViewItem,它應該仍然工作。您可能想要應用第一個Style,但我已包含第二個以防第一個未完全滿足您的要求:

<Style x:Key="ListBoxItemSelectionStyle" TargetType="{x:Type ListBoxItem}"> 
    <Style.Triggers> 
     <Trigger Property="IsKeyboardFocusWithin" Value="True"> 
      <Setter Property="IsSelected" Value="True" /> 
     </Trigger> 
     <Trigger Property="IsKeyboardFocusWithin" Value="False"> 
      <Setter Property="IsSelected" Value="True" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 
<Style x:Key="ListBoxItemSemiSelectionStyle" TargetType="{x:Type ListBoxItem}"> 
    <Style.Triggers> 
     <Trigger Property="IsKeyboardFocusWithin" Value="True"> 
      <Setter Property="IsSelected" Value="True" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 
+0

感謝您的回答。這與我嘗試過的類似,但仍然不夠用。將ListViewItem作爲目標類型與telerik RadGridView一起使用? – aw04

+0

它們是標準'GridView's的容器,所以我想象也適用於'RadGridView'。 – Sheridan