Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按钮。命令不起作用_C#_.net_Wpf_Xaml - Fatal编程技术网

C# 按钮。命令不起作用

C# 按钮。命令不起作用,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我得到了具有以下结构的XAML文件: <UserControl> <Grid> ... <ListBox> <ListBox.ItemTemplate> <DataTemplate> <Expander> <L

我得到了具有以下结构的XAML文件:

<UserControl>
    <Grid>
        ...
        <ListBox>
            <ListBox.ItemTemplate>              
                <DataTemplate>
                    <Expander>
                        <ListBox>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Expander>
                                        <StackPanel>
                                            <kb:Resizer>
                                                <DataGrid>  
                                                    <DataGrid.Columns>  
                                                        ...
                                                            <DataGridTemplateColumn IsReadOnly="True">
                                                                <DataGridTemplateColumn.CellTemplate>
                                                                    <DataTemplate>
                                                                        <Button Style="{StaticResource ChromelessButton}">
                                                                            <Button.CommandParameter>
                                                                                <MultiBinding Converter="{StaticResource MultiBindingConverter}">
                                                                                     <Binding />
                                                                                     <Binding Path="DataContext.Items" RelativeSource="{RelativeSource AncestorType=DataGrid}"/>
                                                                                </MultiBinding>
                                                                            </Button.CommandParameter>
                                                                            <Button.Content>
                                                                                <Image Source="./../Images/close.png" Width="15"></Image>
                                                                            </Button.Content>
                                                                            <Button.Command>                                                            
                                                                                <MultiBinding Converter="{StaticResource TriggerConverter}">
                                                                                    <Binding Path="DataContext.DeleteCommand" 
                                                                                        RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MyClass}}" />
                                                                                    <Binding />
                                                                                </MultiBinding> 
                                                                            </Button.Command>
                                                                        </Button>
                                                                    </DataTemplate>                                             
                                                                </DataGridTemplateColumn.CellTemplate>                                          
                                                            </DataGridTemplateColumn>
                                                        </DataGrid.Columns>  
                                                    </DataGrid> 
                                                </kb:Resizer>                                       
                                            </StackPanel>
                                        </Expander>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Expander>                 
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>

...
...
程序编译和执行正确,输出中没有错误消息,但是
DeleteCommand
从未被命中

我做错了什么?


<Button.Command>                                                            
  <MultiBinding Converter="{StaticResource TriggerConverter}">
     <Binding Path="DataContext.DeleteCommand" 
        RelativeSource="{RelativeSource Mode=FindAncestor, 
                AncestorType={x:Type local:MyClass}}" />
     <Binding />
  </MultiBinding> 
</Button.Command>
代码中的这个xaml看起来有问题

  • 如果在
    DataContext
    中有
    DeleteCommand
    ,那么
    TriggerConverter
    需要什么
  • AncestorType={x:Type local:MyClass}}}
    看起来有误;它是指向某个控件还是指向您的类?我在您的控件层次结构中没有看到此控件(类型为
    MyClass
    )。请检查其工作原理

列表框中的列表框中的数据网格…我不想使用你的应用程序!你在哪里定义了DeleteCommand?用户控件是MyClass吗?