Laden...

Controls in Listview -> SelectedItem -> CommandBinding

Erstellt von chriscolm vor 11 Jahren Letzter Beitrag vor 11 Jahren 1.587 Views
C
chriscolm Themenstarter:in
112 Beiträge seit 2009
vor 11 Jahren
Controls in Listview -> SelectedItem -> CommandBinding

Moinsen,
ich habe ein Listview, dessen Items weitere Controls enthalten (TextBox, CheckBox usw). Damit das ListViewItem selektiert wird, habe ich folgenden Syle definiert:


<ListView.ItemContainerStyle>
	<Style TargetType="{x:Type ListViewItem}">
		<Style.Triggers>
			<Trigger Property="IsKeyboardFocusWithin" Value="True">
				<Setter Property="IsSelected" Value="True"/>
			</Trigger>
		</Style.Triggers>
	</Style>
</ListView.ItemContainerStyle>

Der Teil funktioniert soweit auch. Das Problem welches ich nun habe ist, dass ein CommandBinding nicht mehr Funktioniert.
Im Zusammenhang sieht das etwa so aus:


 <Button Command="{Binding DeleteRecordCommand}"                         
                        Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                    <Image Source="Images/Delete.png"
                           Stretch="None" />
</Button>

<ListView ItemsSource="{Binding Topics}"
                      SelectedItem="{Binding SelectedTopic}"
                      SelectionMode="Single">
                <ListView.InputBindings>
                    <KeyBinding Key="Delete" 
                                Command="{Binding DeleteRecordCommand}" />
                    <KeyBinding Key="Add"
                                Modifiers="Control"
                                Command="{Binding AddRecordCommand}" />
                    <KeyBinding Key="N"
                                Modifiers="Control"
                                Command="{Binding AddRecordCommand}" />
                    <MouseBinding MouseAction="LeftClick"
                                  Command="{Binding AddRecordCommand}" />
                </ListView.InputBindings>    
...               

Der DeleteRecordCommand (ein ICommand), an den der Button gebunden ist, funktioniert nur noch zum Teil, es wird CanExecute noch abgefragt, aber Execute wird nicht ausgeführt, wohingegen das InputBinding vom Listview weiterhin funktioniert.
Nehme ich den Style wieder raus, funktioniert auch wieder der an den Button gebundene Command.

Mit ratlosen Grüßen

Christian