简体   繁体   English

使用鼠标双击事件设置启用组合框

[英]Setting ComboBox enabled using double mouse click event

In my project I have multi-column ListView that contains a ObservableCollection of People objects. 在我的项目中,我有一个多列的ListView,其中包含一个ObservableCollection of People对象。 Their names, schooling areas and other various data form each of the GridViewColumns. 它们的名称,学习区域和其他各种数据构成了每个GridViewColumns。 Some of the GridViewColumns contain a TextBox and others contain a ComboBox. 一些GridViewColumns包含一个TextBox,而另一些包含ComboBox。 I am trying to set the IsEnable property on the locationCmboBx based on a MouseDoubleClick event from one of the other GridViewColumns. 我试图基于其他GridViewColumns之一的MouseDoubleClick事件在locationCmboBx上设置IsEnable属性。 Below I have snippet of my XAML code for the area in question. 下面是有关该区域的XAML代码的片段。

<ListView x:Name="PeopleListView" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,12,0,0" Height="315" Width="560" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding People}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name" Width="80">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox Name="personNameTextBox" Text="{Binding Name, Mode=TwoWay}" IsReadOnly="True" MouseDoubleClick="Control_MouseDoubleClick" Width="80" Background="Transparent" BorderBrush="Transparent"/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>

      <! -- More GridViewColumns Here -->

            <GridViewColumn Header="School" Width="70">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Name="locationCmboBx" ItemsSource="{Binding DataContext.SchoolLocations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" Loaded="OnCmboBxLoad" Width="55" HorizontalAlignment="Center">
                            <ComboBox.Style>
                                <Style TargetType="{x:Type ComboBox}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=SelectedItem.IsEditable, ElementName=GuardbandListView}" Value="False">
                                            <Setter Property="IsEnabled" Value="False" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </ComboBox.Style>
                        </ComboBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
                </GridViewColumn> 

        <! -- More GridViewColumns Here -->   

            </GridView>
        </ListView.View>
    </ListView>

Here I have my IsEditable property that I created for each People object in the ObservableCollection being used to populate the PeopleListView. 在这里,我具有为ObservableCollection中的每个People对象创建的IsEditable属性,该属性用于填充PeopleListView。 This property is set when the user double clicks on one of the cells in a row on the ListView. 当用户双击ListView上一行中的一个单元格时,将设置此属性。 When IsEditable is set to true the IsEnabled property for the locationCmboBx should be set to true as well allowing the user to change the selected value along with the other data in the row. 当IsEditable设置为true时,locationCmboBx的IsEnabled属性也应该设置为true,从而允许用户更改所选值以及该行中的其他数据。

public bool IsEditable
{
    get { return _IsEditable; }

    set
    {
        if (_IsEditable != value)
        {
            _IsEditable = value;
            RaisePropertyChangedEvent("IsEditable");
        }
    }
}

My problem is that I only want the selected row in the PeopleListView to be affected by this event but what is happening is that if I have multiple rows then each ComboBox in each row gets it's IsEnabled property set too. 我的问题是,我只希望PeopleListView中的选定行受此事件影响,但是发生的是,如果我有多行,则每行中的每个ComboBox也会设置为IsEnabled属性。 Anyway around this? 反正这吗?

Use following to trigger double click event, Command Parameters only if you want to pass any else remove it. 仅当您要传递其他事件时,才使用以下命令触发双击事件,命令参数,将其删除。

 <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseDoubleClick">
                <i:InvokeCommandAction Command="{Binding MouseDoubleClickCommand}" CommandParameter="{}" />
            </i:EventTrigger>
</i:Interaction.Triggers>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM