c#mvvm listview绑定selecteditem出错了

时间:2017-09-29 10:04:10

标签: c# mvvm

我有一个C#MVVM应用程序,可以在Windows 7上正常运行,但在Windows XP上无法正常运行。

我有一个客户列表视图,我可以在选定的客户端上执行操作。 xaml 看起来像这样:

<ListView ItemsSource="{Binding Clients}" Grid.Row="1" Grid.Column="0" SelectedValue="{Binding SelectedClient}" e:GridView.AutoSort="True"
                IsTextSearchEnabled="true" TextSearch.TextPath="Name">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding name}" e:GridView.PropertyName="name"
                               Header="{x:Static prop:Resources.Name_Header}" Width="150"/>
                    <GridViewColumn DisplayMemberBinding="{Binding description}" e:GridView.PropertyName="description"
                               Header="{x:Static prop:Resources.Description_Header}" Width="150" />
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{x:Static prop:Resources.Edit_MenuItem}" Command="{Binding EditCommand}" />
                    <MenuItem Header="{x:Static prop:Resources.Dezactivate_MenuItem}" Command="{Binding DeleteCommand}" />
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>

背后的代码:

public IEnumerable<client> Clients
{
    get
    {
        //return from database all the clients
    }
}

private client selectedClient;
public client SelectedClient
{
    get
    {
        return this.selectedClient;
    }
    set
    {
        this.selectedClient = value;
        this.RaisePropertyChanged(() => this.SelectedClient);
        this.EditCommand.RaiseCanExecuteChanged();
        this.DeleteCommand.RaiseCanExecuteChanged();
    }
}

private DelegateCommand<client> editCommand;
public DelegateCommand<client> EditCommand
{
    get
    {
        if (this.editCommand == null)
        {
            this.editCommand = new DelegateCommand<client>(
                o =>
                {
                    var operationVM = this.UnityContainer.Resolve<IClientOperationViewModel>();

                        operationVM.Name = this.SelectedClient.name;
                        operationVM.Description = this.SelectedClient.description;
                        operationVM.IsNew = false;

                        bool? dialogResult = this.UIManagerSvc.ShowDialog(operationVM);
                        if (dialogResult == true)
                        {
                            //edit client
                        }
                },
                c =>
                {
                    return this.SelectedClient != null;
                });
        }
        return this.editCommand;
    }
}

当我选择一个客户端并选择鼠标右键单击时,将打开所选客户端的操作对话框。然后我关闭对话框,选择另一个客户端并进行编辑。对话框将打开,但对于以前的客户端。 这种情况一直发生在Windows XP上,但从未发生在Windows 7上。

有什么想法吗? 提前致谢。 瓦娜

0 个答案:

没有答案
相关问题