Мы используем белый тестовый стек для автоматизации нашего wpf-приложения.
Я пытаюсь получить предметы в шаблонном комбобоксе. Использование combobox sytle и combobox приведено ниже.
var aTypeComboBox = AppHandler.AppWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("MM_GEV_TypeComboBox"));
Код шаблона:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border x:Name="myEDVTypeComboboxBorder"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="myEDVTypeComboboxGrid" SnapsToDevicePixels="True" IsSharedSizeScope="True"
Background="{DynamicResource EDVTypeComboBoxStyle.Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Popup x:Name="myEDVTypeComboboxPopup" AllowsTransparency="True"
IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
Placement="Bottom" Margin="1">
<Border x:Name="myEDVTypeComboboxPopupBorder"
Background="{DynamicResource EDVTypeComboBoxStyle.Background}"
BorderBrush="{DynamicResource EDVTypeComboBoxStyle.BorderBrush}"
BorderThickness="1.1">
<ListBox x:Name="myEDVTypeListBox"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Width="{TemplateBinding ActualWidth}"
ItemsSource="{TemplateBinding ItemsSource}"
SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem}"
Style="{StaticResource DataTypeDescriptionListBoxStyle}" />
</Border>
</Popup>
<ContentPresenter x:Name="myEDVComboboxContentPresenter" Grid.Column="0"
IsHitTestVisible="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" />
<ToggleButton x:Name="myEDVComboboxExpanderArrowToggleButton" Grid.Column="1"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Style="{StaticResource EDVTypeComboBoxReadonlyToggleButtonStyle}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ToggleButton x:Name="myEDVComboboxExpanderToggleButton"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Style="{StaticResource EDVTypeComboBoxExpanderToggleButtonStyle}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
Использование:
<ComboBox x:Name="myMM_GEV_TypeComboBox" Grid.Column="1"
ItemsSource="{Binding Source={StaticResource DataTypeFromEnum}}"
SelectedValue="{Binding SelectedBindingGroupElement.DataType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource EDVTypeComboBoxStyle}"
AutomationProperties.AutomationId="MM_GEV_TypeComboBox" />
Фактический результат: aTypeCombBox существует, но внутренние элементы стремятся к нулю.
Ожидаемый результат: Должны быть элементы aTypeCombBox, чтобы можно было выбрать комбинированный список для нужного элемента.