2016-10-03 7 views
0

Для команды CommandZoomIn CanExecute и Execute не выполняются для элементов управления, определенных в элементе ItemBox ListBox. Метод GraphLcView «CanExecute» и «Execute» вызывается, когда GraphLcView UserControl определяется непосредственно как дочерний элемент AnalysisView, но оба метода никогда не вызывается, когда они добавляются как Item DataTemplate в ItemBox ItemBox.Командное связывание не распространяется для управления в DataTemplate ItemTemplate.

  • Кнопка с командой определена в окне верхнего уровня в ленту.
  • Упрощенная иерархия:
    • (рабочий) Верхнее окно Level -> AnalysisView -> GraphLcView
    • (Не работает) окно верхнего уровня -> AnalysisView -> ListBox + ItemTemplate -> GraphLcView
  • CommandBinding определяются в дочернем элементе управление GraphLcView (UserControl.CommandBinding)
  • Там нет MVVM подразумеваемого в CommandBindind

Обновление: Я создал рабочий образец для демонстрации проблемы, но у меня было другое поведение, чем объяснено здесь. Но полностью работающий образец должен, вероятно, показать что-то похожее на то, что у меня здесь. Потому что bahvior отличается, я спросил another question at StackOverflow. 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> 
+0

Можете ли вы подробнее рассказать о графике и команде. Если возможно, добавьте еще код .. –

+0

Хорошо, это займет несколько часов, но я постараюсь сделать полный рабочий упрощенный образец. –

+0

Полный выбор поможет .. –

ответ

0

Прошу прощения. После расследования я понял, что проблема исходила от контроля LightningChart, который не удерживает фокус. Я добавил 2 обработчика для «GotFocus» и «LostFocus». Затем я понял, что все было хорошо для элемента управления на первой вкладке, которая не является частью ListBox itemTemplate. Но все остальные, находящиеся на второй вкладке, в элемент списка элементов ListBox, потеряли фокус, как только они получили его по какой-либо конкретной причине (по крайней мере, я не могу понять).

Я отправил проблему в компанию Arction под компанией LightningChart, и они сказали мне, что они попытаются исправить ее в ближайшее время.