命令绑定未传播以控制到 ItemTemplate 的 DataTemplate

Command binding is not propagating for control into a DataTemplate of ItemTemplate

对于命令 "CommandZoomIn",CanExecute 和 Execute 不会发生在 ListBox ItemTemplate 中定义的控件。当 GraphLcView UserControl 直接定义为 AnalysisView 的子级时,GraphLcView 方法 "CanExecute" 和 "Execute" 都会被调用,但是当它们被添加为 ListBox ItemTemplate 的 Item DataTemplate 时,这两个方法都不会被调用。

更新:我做了一个工作示例来演示这个问题,但我的行为与这里解释的不同。但是完整的工作样本可能应该显示出与我在这里看到的类似的东西。因为bahvior不一样所以问了. Code is available here at GitHub

用户控件'GraphLcView'部分代码:

<UserControl x:Class="GraphCtrl.GraphView.GraphLcView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

...

<Grid.CommandBindings>
    <CommandBinding Command="{x:Static graphCtrlCommand:CtrlAnalysisCommand.CommandZoomToFitsAll}" CanExecute="CanZoomToFitsAll" Executed="ZoomToFitsAll"/>
    <CommandBinding Command="{x:Static graphCtrlCommand:CtrlAnalysisCommand.CommandZoomIn}" CanExecute="CanZoomIn" Executed="ZoomIn"/>
    <CommandBinding Command="{x:Static graphCtrlCommand:CtrlAnalysisCommand.CommandZoomOut}" CanExecute="CanZoomOut" Executed="ZoomOut"/>

UserControl AnalysisView部分代码(其中使用了之前的GraphLcView UserControl):

                <!-- ********************************-->
                <!-- ********************************-->
                <!-- CommmandBinding works fine here -->
                <!-- ********************************-->
                <!-- ********************************-->
                <graphView1:GraphLcView Grid.Row="1" x:Name="GraphView" Graph="{Binding Graph}" 
                                        Visibility="{Binding IsMain, Converter={StaticResource BooleanToVisibilityConverter1}}"
                                        TrackedSignal="{Binding DataContext.LastTrackedSignal, Mode=TwoWay, ElementName=MyControl}"
                                        SourceTrackedSignal ="{Binding Model.EventTrackingSourceGraphToLegend, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ElementName=MyControl}"
                                        IsMouseInteractive="{Binding IsMouseInteractive}"
                                        UseFastTooltip="{Binding UseFastTooltip}"
                                        ActiveObjectChanged="OnChildActiveObjectChanged"
                                        >
                </graphView1:GraphLcView>

                <Grid Name="GridDetails" Grid.Row="1" >
                    <ListBox Name="ListBoxDetails"  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                         ItemsSource="{Binding Graph.AdditionalViews}"
                         Visibility="{Binding IsDetails, Converter={StaticResource BooleanToVisibilityConverter1}}"
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel IsItemsHost="True"
                                       Name="DetailsWrapPanel"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="Black" BorderThickness="1" Margin="0,1,0,1"
                                        Width="{Binding DataContext.DetailsWorkspaceDimensionX, ElementName=MyControl, Mode=OneWay}"
                                        Height="{Binding DataContext.DetailsWorkspaceDimensionY, ElementName=MyControl, Mode=OneWay}"
                                        >
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"></RowDefinition>
                                            <RowDefinition></RowDefinition>
                                            <RowDefinition Height="Auto"></RowDefinition>
                                        </Grid.RowDefinitions>

                                        <TextBlock Grid.Row="0" Text="{Binding Name}"></TextBlock>

                                        <!-- ********************************-->
                                        <!-- ********************************-->
                                        <!-- Binding does not work fine here -->
                                        <!-- ********************************-->
                                        <!-- ********************************-->

                                        <!--ActiveObjectChanged="GraphLcViewDetailOnActiveObjectChanged"-->
                                        <!--SourceTrackedSignal="{Binding DataContext.EventTypeSourceForSignalTrackingToGraph, Mode=TwoWay, ElementName=MyControl}"-->
                                        <graphView1:GraphLcView Grid.Row="1"
                                            AdditionalView="{Binding Path=., Mode=OneWay}"
                                            Graph="{Binding Graph, ElementName=GraphView}" 
                                            TrackedSignal="{Binding DataContext.LastTrackedSignal, Mode=TwoWay, ElementName=MyControl}"
                                            SourceTrackedSignal ="{Binding Model.EventTrackingSourceGraphToLegend, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ElementName=MyControl}"
                                            IsMouseInteractive="{Binding IsMouseInteractive}"
                                            UseFastTooltip="{Binding UseFastTooltip}"
                                            ActiveObjectChanged="OnChildActiveObjectChanged"
                                            >
                                        </graphView1:GraphLcView>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>

对不起。经过调查,我意识到问题出在LightningChart控件没有保持焦点。我为 "GotFocus" 和 "LostFocus" 添加了 2 个处理程序。然后我意识到第一个选项卡中的控件一切正常,它不是 ListBox itemTemplate 的一部分。但是所有其他位于第二个选项卡中的 ListBox itemTemplate 中的所有其他人,在没有特殊原因的情况下(至少 none 我能理解)一得到它就失去了焦点。

我把这个问题发给了 LightningChart 旗下的公司 Arction,他们告诉我他们会尽快解决。