Question

I'm having a problem with listview in wpf. This is what I have:

<ListView Style="{DynamicResource VirtualisedMetroListView}" SelectedItem="{Binding SelectedCode}" ....... >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <toolkit:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"></toolkit:EventToCommand>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ListView.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                </ListView.Resources>
                <ListView.CacheMode>
                    <BitmapCache/>
                </ListView.CacheMode>
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Style.Triggers>
                            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                                <Setter Property="IsSelected" Value="True"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>

I also have a ribbon with a few buttons such as:

<fluent:RibbonTabItem Header="Try me" Visibility="Visible" Name="cxtTab" >
                <fluent:RibbonGroupBox Header="general">
                    <Button  ContentTemplate="{StaticResource addNewTemplate}"/>                        
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>

Now, I'm using MVVM Light, and I have the Listview SelectedItem binded, but when I click on the button in the ribbon the selectedITem is null and so I cannot delete the item.

Any idea how I can mantain the selectedItem even when I click in other elements (in this case the ribbon)?

Thanks in advance.

Était-ce utile?

La solution

delete this

 <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="IsSelected" Value="True"></Setter>
 </Trigger>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top