0

大家好,我的表单中有可消耗的列表,我想将点击效果绑定到可扩展列表中的项目。到目前为止,一切都很好。我已经设法正确显示可扩展但我无法绑定双击。我在 MVVM Catel 做我的项目。

我的 XAML:

<Grid>
    <ItemsControl ItemsSource="{Binding Source={StaticResource cvsRoutes}}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Expander Header="{Binding Name}" MinHeight="50">
                    <ListBox>
                       <TextBlock Text="Something" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <cmd:EventToCommand Command="{Binding OpenNewWindow}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        </TextBlock>
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                        <TextBlock Text="Something" />
                    </ListBox>
                </Expander>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

在 ModelView 类中我有:

 public RouteViewModel(IMessageService messageService,
        IPleaseWaitService pleaseWaitService, IMapService mapService)
    {
       this.mapService = mapService;
       OpenNewWindow = new Command(CreateNewWindow);
    }

    public Command OpenNewWindow { get; private set; }
    //Method To Open the new window
    public void CreateNewWindow()
    {
        NewWindow.ShowNewWindowMap();
    }
4

1 回答 1

1

您可以查看DoubleClickToCommand行为:

https://catelproject.atlassian.net/wiki/display/CTL/DoubleClickToCommand

该链接包含有关行为的信息以及有关如何使用它的示例,我在下面复制了这些信息:

<ListBox x:Name="listBox" ItemsSource="{Binding PersonCollection}" SelectedItem="{Binding SelectedPerson}">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <Grid>
        <i:Interaction.Behaviors>
          <catel:DoubleClickToCommand Command="{Binding ElementName=listBox, Path=DataContext.Edit}" />
        </i:Interaction.Behaviors>

        <StackPanel Orientation="Horizontal">
          <Label Content="{Binding FirstName}" />
          <Label Content="{Binding MiddleName}" />
          <Label Content="{Binding LastName}" />
        </StackPanel>
      </Grid>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>
于 2014-08-13T13:54:47.250 回答