2
<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">                                                                     
                    <ListView.ItemContainerStyle>
                       <Style TargetType="{x:Type ListViewItem}">
                          <Setter Property="HorizontalContentAlignment" Value="Stretch" />                            <Setter Property="Padding" Value="2"/>
                          <EventSetter Event="MouseDoubleClick" Handler="ItemsControl_SelectionChanged"/>
                                                        </Style>
                                                    </ListView.ItemContainerStyle>

リストビューの選択が変更されたときに、いくつかの仕事をしたいと思います。スタイルを使用しているため、ListViewでSelectionChangedイベントを使用できません。EventSetterを使用しようとしましたが、プロジェクトのコンパイル中にエラーが発生しました。

イベント「MouseDoubleClick」は、スタイルのターゲットタグに指定できません。代わりにEventSetterを使用してください。

誰か助けてくれませんか?

4

2 に答える 2

6

スタイルをインラインで宣言するのではなく、リソースとして作成してみてください。動作が異なる理由はわかりませんが、エラーが解消されるようです:

<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}"/>
于 2010-06-29T12:15:35.517 に答える
1

「私はスタイルを使用しているため、ListView で SelectionChanged イベントを使用できません」というステートメントを理解できません

ただし、Style も使用している場合は、Listview の SelectionChanged イベントを使用できます。

于 2010-06-29T10:35:44.493 に答える