WPF ListView SelectionChanged inside style does not work. EventSetter either

江枫思渺然 提交于 2019-11-29 16:11:34

Try creating the Style as a resource instead of declaring it inline. I don't know why it behaves differently, but it appears to make the error go away:

<Style TargetType="{x:Type ListViewItem}" x:Key="ItemContainerStyle">
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Padding" Value="2"/>
    <EventSetter Event="MouseDoubleClick" Handler="ItemsControl_SelectionChanged"/>
</Style>
<Style x:Key="OrderGroupTemplateStyle" TargetType="{x:Type ContentControl}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Name.ShowDetailedInfo, UpdateSourceTrigger=PropertyChanged}" Value="False">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="3" Margin="2">
                            <StackPanel Background="LightGoldenrodYellow">
                                <ContentControl Content="{Binding Path=.}" Style="{StaticResource MyRecordViewModelShortStyle}"/>
                                <ListView ItemsSource="{Binding Path=Items}" Margin="4" ItemContainerStyle="{StaticResource ItemContainerStyle}"/>

I don't understand statement 'because I am using style I cannot use SelectionChanged Event on ListView'

But you can use SelectionChanged event of Listview, if you are using Style also.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!