Scrollbar issues with WPF - c#

In the following XAML I have two issues, the first is that despite disabling the horizontal scrollbar on the main scrollviewer it still shows, the second is that I have set a style on the textbox (notes) to display a vertical scrollbar but it does not display
<UserControl x:Class="VTUK.Gemini.Contacts.ContactsDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:views="clr-namespace:VTUK.Gemini.Contacts"
mc:Ignorable="d"
d:DesignHeight="1200" d:DesignWidth="1200">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/VTUK.Gemini.Infrastructure;component/Styles/Brushes.xaml"/>
<ResourceDictionary Source="pack://application:,,,/VTUK.Gemini.Infrastructure;component/Styles/CommonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<DataTemplate x:Key="ContactsReadOnlyTemplate">
<Grid Name="Grid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Name="HeaderPanel" Orientation="Horizontal">
<Border BorderThickness="2" BorderBrush="{StaticResource Windows8BlueBrush}" Margin="5" >
<!--Phone3 is here as a temporary value-->
<telerik:RadTransitionControl Margin="5" Content="{Binding Phone3, FallbackValue='pack://application:,,,/VTUK.Gemini.Infrastructure;component/Images/businessperson2.png', Converter={StaticResource ImageSourceToBitmapConverter}}" Duration="0:0:1" IsTabStop="False">
<telerik:RadTransitionControl.Transition>
<!--<telerik:MotionBlurredZoomTransition/>-->
<telerik:FlipWarpTransition/>
</telerik:RadTransitionControl.Transition>
<telerik:RadTransitionControl.ContentTemplate>
<DataTemplate>
<Image Source="{Binding .}" Width="64" Height="64" />
</DataTemplate>
</telerik:RadTransitionControl.ContentTemplate>
</telerik:RadTransitionControl>
</Border>
</StackPanel>
<ScrollViewer x:Name="ScrollViewer" Width="{Binding ElementName=LayoutRoot, Path=ActualWidth}" Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" BorderThickness="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="45" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="45" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
<RowDefinition Height="Auto" MinHeight="28" />
</Grid.RowDefinitions>
<TextBlock Text="DISPLAY NAME" Style="{StaticResource Heading14}" />
<TextBlock Text="TITLE" Style="{StaticResource Heading14}" Grid.Row="1" Grid.Column="0" />
<TextBlock Text="FORENAME" Style="{StaticResource Heading14}" Grid.Row="2" Grid.Column="0"/>
<TextBlock Text="SURNAME" Style="{StaticResource Heading14}" Grid.Row="3" Grid.Column="0"/>
<TextBlock Text="HOUSE NAME / NO." Style="{StaticResource Heading14}" Grid.Row="4" Grid.Column="0"/>
<TextBlock Text="ADDRESS1" Style="{StaticResource Heading14}" Grid.Row="5" Grid.Column="0"/>
<TextBlock Text="ADDRESS2" Style="{StaticResource Heading14}" Grid.Row="6" Grid.Column="0"/>
<TextBlock Text="TOWN" Style="{StaticResource Heading14}" Grid.Row="7" Grid.Column="0"/>
<TextBlock Text="COUNTY" Style="{StaticResource Heading14}" Grid.Row="8" Grid.Column="0"/>
<TextBlock Text="COUNTRY" Style="{StaticResource Heading14}" Grid.Row="9" Grid.Column="0"/>
<TextBlock Text="POSTCODE" Style="{StaticResource Heading14}" Grid.Row="10" Grid.Column="0"/>
<TextBlock Text="EMAIL" Style="{StaticResource Heading14}" Grid.Row="11" Grid.Column="0"/>
<TextBlock Text="PHONE !" Style="{StaticResource Heading14}" Grid.Row="12" Grid.Column="0"/>
<TextBlock Text="PHONE 2" Style="{StaticResource Heading14}" Grid.Row="13" Grid.Column="0"/>
<TextBlock Text="PHONE 3" Style="{StaticResource Heading14}" Grid.Row="14" Grid.Column="0"/>
<TextBlock Text="URL" Style="{StaticResource Heading14}" Grid.Row="15" Grid.Column="0"/>
<TextBlock Text="NOTES" Style="{StaticResource Heading14}" Grid.Row="16" Grid.Column="0" VerticalAlignment="Top"/>
<TextBlock Text="{Binding DisplayName}" TextWrapping="Wrap" FontSize="22" FontWeight="DemiBold" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" />
<TextBlock Text="{Binding Title}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="1" />
<TextBlock Text="{Binding Forename}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="2" />
<TextBlock Text="{Binding Surname}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="3" />
<TextBlock Text="{Binding HouseNameNo}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="4" />
<TextBlock Text="{Binding Address1}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="5" />
<TextBlock Text="{Binding Address2}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="6" />
<TextBlock Text="{Binding Town, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="7" />
<TextBlock Text="{Binding County, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="8" />
<TextBlock Text="{Binding Country, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="9" />
<TextBlock Text="{Binding Postcode, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="10" />
<TextBlock Text="{Binding Email}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="11" />
<TextBlock Text="{Binding Phone1}" TextWrapping="Wrap" FontSize="22" FontWeight="DemiBold" Grid.Column="2" Grid.Row="12" VerticalAlignment="Center" />
<TextBlock Text="{Binding Phone2}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="13" />
<TextBlock Text="{Binding Phone3}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="14" />
<TextBlock x:Name="URLContainer" Text="http://www.google.com" Visibility="Collapsed" />
<telerik:RadButton x:Name="linkButton"
VerticalAlignment="Center"
Margin="0"
Content="{Binding Text, ElementName=URLContainer}"
Grid.Column="2" Grid.Row="15"
Style="{StaticResource HyperlinkStyleButton14}"
Command="{Binding NavigateToUrlCommand}" CommandParameter="{Binding Text, ElementName=URLContainer}"
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=views:ContactsContent, AncestorLevel=1}}" />
<TextBox Grid.Column="2" Grid.Row="16"
Text="{Binding ContactNotes}"
Style="{DynamicResource CustomTextBoxStyle}" />
<!--Visibility="{Binding ContactNotes, Converter={StaticResource StringToVisibilityConverter}}" />-->
</Grid>
</ScrollViewer>
</Grid>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<telerik:RadDataForm x:Name="DataForm"
ItemsSource="{Binding Contacts}"
CommandButtonsVisibility="Cancel,Commit"
AutoGenerateFields="False"
ValidationSummaryVisibility="Visible"
LabelPosition="Above"
ReadOnlyTemplate="{StaticResource ContactsReadOnlyTemplate}"
VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" />
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
<telerik:RadButton RenderTransformOrigin="0.5,0.5" Margin="0,0,40,0" Tag="ADD"
Command="telerik:RadDataFormCommands.AddNew" CommandTarget="{Binding ElementName=DataForm}">
<Path Stretch="None" Data="M6,0 L10,0 L10,6 L16,6 L16,10 L10,10 L10,16 L6,16 L6,10 L0,10 L0,6 L6,6 z"
SnapsToDevicePixels="True" />
</telerik:RadButton>
<telerik:RadButton Command="telerik:RadDataFormCommands.BeginEdit" CommandTarget="{Binding ElementName=DataForm}" Tag="EDIT">
<Path Stretch="Fill" Data="F1 M233.5498,613.749 C233.9048,613.662,233.9828,613.379,233.7238,613.123 L232.1378,611.544 C231.8808,611.288,231.5968,611.367,231.5098,611.718L230.9968,613.784C230.9088,614.139,231.1258,614.355,231.4808,614.267z M249.4978,595.808C247.7348,594.047,245.9968,595.404,245.9968,595.404C245.7078,595.627,245.2668,596.019,245.0118,596.269C244.7588,596.521,244.7638,596.939,245.0198,597.196L248.1078,600.281C248.3648,600.54,248.7828,600.544,249.0388,600.29C249.2918,600.036,249.6808,599.594,249.9038,599.307C249.9038,599.307,251.2638,597.572,249.4978,595.808 M237.2018,612.109C236.9458,612.369,236.5228,612.369,236.2668,612.109L233.1778,609.025C232.9208,608.768,232.9208,608.349,233.1778,608.09L243.0538,598.228C243.3108,597.971,243.7318,597.971,243.9898,598.228L247.0738,601.312C247.3328,601.571,247.3328,601.993,247.0738,602.248z"
Height="16" Width="16"
SnapsToDevicePixels="True" />
</telerik:RadButton>
</StackPanel>
<telerik:RadBusyIndicator IsIndeterminate="True"
IsBusy="{Binding IsBusy}" DisplayAfter="0:0:0.2"
telerik:AnimationManager.IsAnimationEnabled="True"/>
</Grid>
</UserControl>
<!-- Texybox with scrollviewer-->
<Style x:Key="CustomTextBoxStyle" TargetType="TextBox">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderBrush" Value="{x:Null}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid x:Name="RootElement" UseLayoutRounding="True">
<ScrollViewer x:Name="PART_ContentHost"
Padding="{TemplateBinding Padding}"
Foreground="{TemplateBinding Foreground}"
Background="{x:Null}"
BorderBrush="{x:Null}"
BorderThickness="0"
Margin="0"
VerticalScrollBarVisibility="Visible" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Related

WPF XAML resize <infrastructure:Plugin> width to the content in it

I have an interface with some tabs in it on the right side of the screen. I need each tab`s width to be resized by width of the context in it.
All the other tabs do it apart from this one...
Any suggestions, please?
Description
The scales tab in the stackup editor doesn’t resize when selected.
Select the scales tab on the right side of the stackup editor
Right hand tab doesn’t resize
Expected Behaviour
Tab resizes to fit content, as with all other tabs in the stackup
editor
enter image description here
<infrastructure:Plugin x:Class="Xact.GeminiX.Plugin.PanelEditors.Views.DisplayScalesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infrastructure="clr-namespace:Xact.GeminiX.Client.Common.Infrastructure;assembly=Xact.GeminiX.Client.Common"
xmlns:converters="clr-namespace:Xact.GeminiX.Client.Wpf.Common.Converters;assembly=Xact.GeminiX.Client.Wpf.Common"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
LayoutUpdated="ViewLayoutUpdated"
Loaded="Plugin_Loaded">
<infrastructure:Plugin.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
<converters:BooleanToVisibilityHiddenOnFalseConverter x:Key="BooleanToVisibilityHiddenOnFalseConverter"></converters:BooleanToVisibilityHiddenOnFalseConverter>
<infrastructure:DataContextProxy x:Key="DataContextProxy"/>
</infrastructure:Plugin.Resources>
<i:Interaction.Behaviors>
<infrastructure:DataContextProxyBehavior DataContextProxy="{StaticResource DataContextProxy}"/>
</i:Interaction.Behaviors>
<Grid Grid.IsSharedSizeScope="True" PreviewMouseWheel="UIElement_OnPreviewMouseWheel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.Resources>
<ContextMenu x:Key="ImportContextMenu"
ItemsSource="{Binding DataContext.ScalingImportExportMetaData.ScalingImportFormats, Source={StaticResource DataContextProxy}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header"
Value="{Binding FormatTitle}"/>
<Setter Property="Command"
Value="{Binding DataContext.FormatSelectionCommand, Source={StaticResource DataContextProxy}}"/>
<Setter Property="CommandParameter"
Value="{Binding}"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
<ContextMenu x:Key="ImportFromStackupContextMenu">
<MenuItem Header="{Binding StoredLocalisation}" Click="ButtonImportFromStackupStored_OnClick"/>
<MenuItem Header="{Binding RemakesLocalisation}" Click="ButtonImportFromStackupRemakes_OnClick"/>
</ContextMenu>
<ContextMenu x:Key="ContextMenu" ItemsSource="{Binding DataContext.ScalingImportExportMetaData.ScalingExportFormats, Source={StaticResource DataContextProxy}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header"
Value="{Binding FormatTitle}"/>
<EventSetter Event="Click"
Handler="MenuItem_OnClick"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
<DataTemplate x:Key="ExportButtonTemplate">
<telerik:RadButton Content="{Binding TypeTitle}" Click="ButtonBase_OnClick" IsEnabled="{Binding Enabled}" ContextMenu="{StaticResource ContextMenu}" Margin="2"/>
</DataTemplate>
</Grid.Resources>
<ScrollViewer VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
Grid.Column="0">
<Grid>
<Grid.Resources>
<converters:BooleanInvertConverter x:Key="BooleanInvertConverter"></converters:BooleanInvertConverter>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" SharedSizeGroup="B"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" SharedSizeGroup="C"/>
<RowDefinition Height="Auto" SharedSizeGroup="D"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Loaded="TopGrid_OnLoaded" HorizontalAlignment="Left" x:Name="Grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding LayerLocalisation}" Margin="5" />
<TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding FirstScaleFactorLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Text="{Binding SecondScaleFactorLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding ArtworkLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding PredictedLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="3" Text="{Binding ArtworkLocalisation}" HorizontalAlignment="Center" Margin="5" />
<TextBlock Grid.Row="1" Grid.Column="4" Text="{Binding PredictedLocalisation}" HorizontalAlignment="Center" Margin="5" />
<Border Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="5"
BorderThickness="0, 1, 0, 0"
Margin="0, 5, 0, 5"
BorderBrush="LightGray" />
<TextBlock Grid.Row="3"
Grid.Column="0"
Text="{Binding AllLocalisation}"
VerticalAlignment="Center"
Margin="5" />
<TextBox x:Name="EnabledTemplate"
Grid.Row="3"
Grid.Column="1"
Margin="5"
Text="{Binding ShortValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
KeyDown="SetShortValues_OnKeyDown"
TextChanged="ShortValueTextbox_TextChanged"
Width="80"
IsEnabled="{Binding ScalesExist}"
MaxLength="10" />
<telerik:RadButton Grid.Row="3"
Grid.Column="2"
Content="{Binding SetFirstLocalisation}"
Click="SetShortButton_OnClick"
IsEnabled="{Binding ScalesExist}"
Margin="2"/>
<TextBox Grid.Row="3"
Grid.Column="3"
Margin="5"
Text="{Binding LongValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
KeyDown="SetLongValues_OnKeyDown"
TextChanged="ShortValueTextbox_TextChanged"
Width="80"
IsEnabled="{Binding ScalesExist}"
MaxLength="10" />
<telerik:RadButton Grid.Row="3"
Grid.Column="4"
Content="{Binding SetSecondLocalisation}"
Click="SetLongButton_OnClick"
IsEnabled="{Binding ScalesExist}"
Margin="2"/>
<CheckBox Grid.Row="4"
Grid.Column="0"
IsEnabled="{Binding ScalesExist}"
IsChecked="{Binding AllCheckboxIsChecked}"
Margin="5"
Click="SetAllCheckBoxToggled" />
<telerik:RadButton Grid.Row="4"
Grid.Column="2"
Content="{Binding PredictedSwapLocalisation}"
Click="PredictedShortButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
AutomationProperties.AutomationId="PredictedShortButtonID"
x:Name="PredictedShortButtonID"
Margin="2"/>
<telerik:RadButton Grid.Row="4"
Grid.Column="4"
Content="{Binding PredictedSwapLocalisation}"
Click="PredictedLongButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
AutomationProperties.AutomationId="PredictedLongButtonID"
x:Name="PredictedLongButtonID"
Margin="2"/>
<Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="5" BorderThickness="0, 1, 0, 0" Margin="0, 10, 0, 10" BorderBrush="LightGray" />
</Grid>
<Grid Grid.Row="1">
<ScrollViewer HorizontalAlignment="Left" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Name="ScrollViewer" ScrollChanged="ScrollViewer_OnScrollChanged">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="RowsTemplate">
<Grid x:Name="TemplateGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" IsChecked="{Binding IsChecked}" VerticalAlignment="Center" Margin="5" IsEnabled="{Binding Editable}"
Command="{Binding Path=DataContext.CheckBoxChangedCommand, ElementName=Grid}" CommandParameter="{Binding}" />
<TextBlock Grid.Column="1" Text="{Binding Layer}" VerticalAlignment="Center" Margin="5" />
</Grid>
<TextBox Grid.Column="1"
Text="{Binding ShortDisplayValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Editable}"
Width="80"
Margin="5"
TextChanged="ShortValueTextbox_TextChanged"
KeyDown="FirstUIElement_OnKeyDown"
LostFocus="FirstUIElement_OnLostFocus" />
<telerik:RadButton Grid.Column="2"
Command="{Binding Path=DataContext.SetSinglePredictedShortCommand, ElementName=Grid}"
CommandParameter="{Binding}"
IsEnabled="{Binding Editable}"
Visibility="{Binding Visible}" HorizontalContentAlignment="Left"
Margin="2">
<telerik:RadButton.Content>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Label Background="{Binding ConfidenceBrush}" Foreground="{Binding ConfidenceForegroundBrush}" Height="20" Width="20" Content="{Binding ConfidenceCharacter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0"></Label>
<TextBlock Text="{Binding ShortButton}" />
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
<TextBox Grid.Column="3"
Text="{Binding LongDisplayValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Editable}"
Width="80"
Margin="5"
TextChanged="ShortValueTextbox_TextChanged"
KeyDown="SecondUIElement_OnKeyDown"
LostFocus="SecondUIElement_OnLostFocus" />
<telerik:RadButton Grid.Column="4"
Command="{Binding Path=DataContext.SetSinglePredictedLongCommand, ElementName=Grid}"
CommandParameter="{Binding}"
IsEnabled="{Binding Editable}"
Visibility="{Binding Visible}" HorizontalContentAlignment="Left"
Margin="2">
<telerik:RadButton.Content>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Label Background="{Binding ConfidenceBrush}" Foreground="{Binding ConfidenceForegroundBrush}" Height="20" Width="20" Content="{Binding ConfidenceCharacter}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0"></Label>
<TextBlock Text="{Binding LongButton}" />
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</Grid>
</DataTemplate>
</Grid.Resources>
<ItemsControl ItemTemplate="{StaticResource RowsTemplate}" ItemsSource="{Binding Rows}" />
</Grid>
</ScrollViewer>
</Grid>
<Border Grid.Row="2" BorderThickness="0, 1, 0, 0" Margin="0, 0, 0, 10" BorderBrush="LightGray" />
<Grid Grid.Row="3" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="A" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<telerik:RadButton Grid.Row="0" Grid.Column="0"
Content="{Binding SwapAllLocalisation}"
Click="SwapAllButton_OnClick"
IsEnabled="{Binding ScalesExist}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="1"
Content="{Binding SetAllPredictedLocalisation}"
Click="SetAllPredictedButton_OnClick"
IsEnabled="{Binding PredictionsAvailable}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="2"
Content="{Binding ResetLocalisation}"
Click="ResetButton_OnClick"
IsEnabled="{Binding ScalesExist}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="0" Grid.Column="3"
Content="{Binding ArtworkRevisionsLocalisation}"
Click="ArtworkRevisionsButton_OnClick"
HorizontalAlignment="Center"
IsEnabled="{Binding ArtworksButtonEnabled}"
Visibility="{Binding ArtworksButtonVisible, Converter={ StaticResource BooleanToVisibilityHiddenOnFalseConverter}}"
Margin="2"/>
<telerik:RadButton Grid.Row="1" Grid.Column="0"
Content="{Binding ImportLocalisation}"
Click="ButtonImport_Click"
IsEnabled="{Binding ScalesExist}"
ContextMenu="{StaticResource ImportContextMenu}"
HorizontalAlignment="Center"
Margin="2"/>
<telerik:RadButton Grid.Row="1" Grid.Column="1"
Content="{Binding StackupImportLocalisation}"
Click="ButtonImportFromStackup_OnClick"
ContextMenu="{StaticResource ImportFromStackupContextMenu}"
IsEnabled="{Binding CanImportFromStackup}"
Visibility="{Binding ImportFromStackupEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
HorizontalAlignment="Center"
Margin="2"/>
<ItemsControl Grid.Row="1" Grid.Column ="2" Grid.ColumnSpan="2" ItemsSource="{Binding ScalingImportExportMetaData.ScalingExportTypes}" ItemTemplate="{StaticResource ExportButtonTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.ColumnSpan="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock Text="{Binding SingleCoresLocalisation}" VerticalAlignment="Center"/>
<RadioButton IsChecked="{Binding UseSingleCores}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock Text="{Binding IndividualCopperLocalisation}" VerticalAlignment="Center"/>
<RadioButton IsChecked="{Binding UseSingleCores, Converter={ StaticResource BooleanInvertConverter}}" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
</Grid>
</Grid>
</ScrollViewer>
<Grid Grid.Column="1">
<Grid.Resources>
<converters:NonZeroDoubleToVisibilityConverter x:Key="NonZeroDoubleToVisibilityConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="B"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition SharedSizeGroup="C"></RowDefinition>
<RowDefinition SharedSizeGroup="D"></RowDefinition>
</Grid.RowDefinitions>
<ScrollBar Grid.Row="1" Minimum="0" SmallChange="1" LargeChange="10"
ViewportSize="{Binding ViewportHeight, ElementName=ScrollViewer}"
Maximum="{Binding ScrollableHeight, ElementName=ScrollViewer}"
Scroll="ScrollBar_OnScroll" Name="ScrollBar"
Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Maximum, Converter={StaticResource NonZeroDoubleToVisibilityConverter}}" />
</Grid>
</Grid>
</infrastructure:Plugin>

Not able to get the current active /selected TabITem in DevExpress DxTabControl in WPF

I have a WPF app and I am trying to Automate it using FlaUI. I am facing a problem with the DxTabControl. I have provided Automation IDs to the DxTabControl. I am using DXTabControl.ItemHeaderTemplate to generate TabItems dynamically.
According to DevExpress Team, The DXTabControl.ItemHeaderTemplate doesnt support AutoamtionPeer so a custom implementation has been added to override its default behaviour.
Now, I am able to see the TabControl and the TabItems in the Inspect.exe.
Now , my requirement is to Access the currently selected Tabitem and find the CloseButton using the AutoamtionID mentioned in the XAML below and close it. Pasting below the line again. As there would be multiple TabItems generated, I am unable to get the Currently active/Selected TabItem .
The XAML is below
<dx:DXTabControl AutomationProperties.AutomationId="ViewsParentTabControl"
MaxWidth="4000"
MaxHeight="4000"
Margin="1,0,-1,0"
Focusable="False"
ItemsSource="{Binding OpenViews}"
SelectedIndex="{Binding SelectedTabIndex}"
TabContentCacheMode="CacheTabsOnSelecting">
<dx:DXTabControl.ItemHeaderTemplate>
<DataTemplate DataType="viewModels1:OpenViewDefinitionViewModel">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Name="CreatedViewName"
MaxWidth="100"
Text="{Binding Data.ViewDefinition.Name}"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding DisplayName}" />
<TextBlock Grid.Row="0" Grid.Column="1"><Run Text=" [" /><Run Text="{Binding ItemsCount, FallbackValue=0, Mode=OneWay}" /><Run Text="]" /></TextBlock>
<controls2:ProgressIndicator AutomationProperties.AutomationId="ProgressCurrentView"
Grid.Row="0"
Grid.Column="3"
Width="14"
Margin="4,0,0,0"
VerticalAlignment="Center"
CircleBorder="{StaticResource ListBoxItem.Foreground}"
CircleFill="{StaticResource ListBoxItem.Foreground}"
IndicatorEnabled="{Binding IsDataLoading}" />
<Button AutomationProperties.AutomationId="CloseCurrentViewButton"
Grid.Row="0"
Grid.Column="2"
Width="10"
Height="10"
Margin="10,1,0,0"
Padding="0"
HorizontalAlignment="Right"
BorderThickness="0"
Command="{Binding DataContext.CloseItemCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=dx:DXTabControl}}"
CommandParameter="{Binding}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Close">
<Path
Data="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z"
Fill="White"
Stretch="Fill" />
</Button>
</Grid>
</DataTemplate>
</dx:DXTabControl.ItemHeaderTemplate>
<dx:DXTabControl.ItemTemplate>
<DataTemplate DataType="viewModels1:OpenViewDefinitionViewModel">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<local:VoyagesGridControl />
<local:VoyageValidationUserControl
Grid.Row="1"
Grid.Column="0"
MinHeight="100"
MaxHeight="300"
Visibility="{Binding Path=IsVoyageValidationShowing, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
<local:VoyageHistoryUserControl
Grid.Row="2"
Grid.Column="0"
MinHeight="300"
MaxHeight="300"
Visibility="{Binding Path=IsVoyageHistoryShowing, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
<local:VesselHistoryUserControl
Grid.Row="3"
Grid.Column="0"
MinHeight="300"
MaxHeight="300"
Visibility="{Binding Path=IsVesselHistoryShowing, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
<local:VoyageEvents
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="1"
VerticalAlignment="Top"
Visibility="{Binding Path=IsVoyageEventsShowing, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
<controls2:ProgressIndicator AutomationProperties.AutomationId="showProgressForLoadingViews"
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="0"
Width="80"
HorizontalAlignment="Center"
VerticalAlignment="Center"
CircleBorder="{StaticResource ListBox.BorderBrush}"
CircleFill="{StaticResource ListBox.BorderBrush}"
IndicatorEnabled="{Binding IsDataLoading}" />
<!-- Buttons -->
<Grid Grid.Row="4" Grid.Column="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock Style="{StaticResource MwTextBlockLabelStyle}" Text="Last Refresh:" />
<TextBlock
Margin="2,0,4,0"
VerticalAlignment="Center"
Text="{Binding LoadDate, StringFormat=G}" />
</StackPanel>
<Button AutomationProperties.AutomationId="AddNewVoyageButton"
Grid.Row="0"
Grid.Column="1"
Padding="0"
Command="{Binding AddVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Add a new voyage to this View (ALT + A)">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Add}" />
<Label Style="{StaticResource MwLabelStyle}">_Add</Label>
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="refreshVoyageButton"
Grid.Row="0"
Grid.Column="2"
Padding="0"
Command="{Binding RefreshVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Refresh the this View (modified entries are left unchanged)">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Refresh}" />
<TextBlock Style="{StaticResource MwTextBlockLabelStyle}" Text="Refresh" />
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="showVoyageHistroyButton"
Grid.Column="4"
Margin="2,2,2,2"
Padding="0"
VerticalAlignment="Center"
Command="{Binding ShowVoyageHistoryCommand}"
Focusable="False"
ToolTip="Show the selected voyage's change history"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource ShowVoyageHistory}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Hide Voyage History"
Visibility="{Binding IsVoyageHistoryShowing, Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Show Voyage History"
Visibility="{Binding IsVoyageHistoryShowing, Converter={StaticResource MwBoolToVisibilityConverterReverse}}" />
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="showVesselHistroyButton"
Grid.Column="5"
Margin="2,2,2,2"
Padding="0"
VerticalAlignment="Center"
Command="{Binding ShowVesselHistoryCommand}"
Focusable="False"
ToolTip="Show the selected vessel's voyage history"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource ShowVesselHistory}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Hide Vessel History"
Visibility="{Binding IsVesselHistoryShowing, Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Show Vessel History"
Visibility="{Binding IsVesselHistoryShowing, Converter={StaticResource MwBoolToVisibilityConverterReverse}}" />
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="showVoyageButton"
Grid.Column="6"
Margin="2,2,2,2"
Padding="0"
VerticalAlignment="Center"
Command="{Binding ShowVesselVisitsCommand}"
Focusable="False"
ToolTip="Show the selected voyage's events"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Anchor}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Hide Voyage Events"
Visibility="{Binding IsVoyageEventsShowing, Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBlock
Style="{StaticResource MwTextBlockLabelStyle}"
Text="Show Voyage Events"
Visibility="{Binding IsVoyageEventsShowing, Converter={StaticResource MwBoolToVisibilityConverterReverse}}" />
</StackPanel>
</Button>
<Border Grid.Row="0" Grid.Column="8">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDuplicateView, Mode=TwoWay}" Value="true">
<Setter Property="Background" Value="LightGreen" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Button AutomationProperties.AutomationId="DuplicateCheckButton"
Padding="0"
Command="{Binding DuplicateVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Switch to duplicate Voyages (ALT + D)"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Duplicate}" />
<AccessText Style="{StaticResource MwAccessTextLabelStyle}" Text="{Binding VoyageDuplicateText}" />
</StackPanel>
</Button>
</Border>
<Button AutomationProperties.AutomationId="PublishVoyagesButton"
Grid.Row="0"
Grid.Column="9"
Padding="0"
Command="{Binding PublishVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Publish any modified Voyages (ALT + P)"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Publish}" />
<AccessText Style="{StaticResource MwAccessTextLabelStyle}" Text="{Binding VoyagePublishText}" />
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="UndoSingleVoyageButton"
Grid.Row="0"
Grid.Column="10"
Padding="0"
Command="{Binding UndoSingleChangedVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Locally Undo unpublished changes to the selected voyage"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Undo}" />
<TextBlock Style="{StaticResource MwTextBlockLabelStyle}" Text="Undo Selected" />
</StackPanel>
</Button>
<Button AutomationProperties.AutomationId="UndoandUnpublishVoyageButton"
Grid.Row="0"
Grid.Column="11"
Padding="0"
Command="{Binding UndoChangedVoyagesCommand}"
Focusable="False"
Style="{StaticResource MwButtonStyle}"
ToolTip="Locally Undo any changed and unpublished voyages"
Visibility="{Binding Data.ViewDefinition.IsInternalView, Converter={StaticResource MwBoolToVisibilityConverterReverse}}">
<StackPanel Orientation="Horizontal">
<ContentControl Height="26" Content="{StaticResource Undo}" />
<TextBlock Style="{StaticResource MwTextBlockLabelStyle}" Text="Undo All" />
</StackPanel>
</Button>
</Grid>
</Grid>
</DataTemplate>
</dx:DXTabControl.ItemTemplate>
</dx:DXTabControl>
My FlaUIapproach of locating the Controls is below
public IMainWindow ConfirmCreatedView()
{
_logger.Info("Checking the newly created View on the screen");
//Apoorv: Need to find TabItem here
_controlAction.Highlight(ViewsTabControl); // This highlights the TabControl- Works
int NumberOfActiveTabs = ViewsTabControl.TabItems.Length; // This gives me no of TabItems
TabItem SelectedTab= ViewsTabControl.SelectedTabItem as TabItem; // Gives me Null here
var newTab = ViewsTabControl.SelectedTabItemIndex ; // Give me -1 here
_controlAction.Highlight(ViewsTabControl.TabItems[2]); // Works. It highlights the TabItem at position 2
_controlAction.ClickWait<TabItem>(ViewsTabControl.TabItems[2]); // This goes and clicks the tab item
TabItem SelectedTabs = ViewsTabControl.SelectedTabItem as TabItem;
var check = ViewsTabControl.TabItems[2].FindAllChildren();
// TabItem ti = ViewsTabControl.SelectedItem as TabItem;
//_controlAction.Highlight()
_controlAction.Highlight(CloseCurrentView); // highlights the close button atTabItem[0]
_controlAction.Click<Button>(CloseCurrentView); // closes it
return this;
}
I am using FlaUI to Find the TabControl using AutomationID as shown below
private Tab ViewsTabControl => _uiAutomation.FindElement("ViewsParentTabControl", Automation.FindBy.Id).AsTab();
private TabItem ViewsTabItem => _uiAutomation.FindElement("DXTabItem", Automation.FindBy.Id).AsTabItem();
I would like to find the curently active TabItem based on the Index and then go and click the close button by automating it.
TabItem SelectedTab= ViewsTabControl.SelectedTabItem as TabItem; // Gives me Null here
var newTab = ViewsTabControl.SelectedTabItemIndex ; // Give me -1 here
It is not TabItem it is DXTabItem. This is the type you should cast to.
DXTabItem SelectedTab = ViewsTabControl.SelectedTabItem as DXTabItem;
DevEXpress don't create automation peers for controls within ItemHeaderTemplate. It will be necessary to use a custom automation peer to provide this functionality. For example, I used the following class for test purposes:
public class DXTabItemAutomationPeerEx : DXTabItemAutomationPeer, ISelectionItemProvider {
private DXTabItem TabItem => base.Owner as DXTabItem;
private DXTabControl TabControl => TabItem.With((DXTabItem x) => x.Owner);
public DXTabItemAutomationPeerEx(DXTabItem ownerCore) : base(ownerCore) { }
protected override List<AutomationPeer> GetChildrenCore() {
List<AutomationPeer> children = base.GetChildrenCore();
foreach (var button in LayoutTreeHelper.GetVisualChildren(Owner).OfType<Button>())
children.Add(new ButtonAutomationPeer(button));
return children;
}
bool ISelectionItemProvider.IsSelected { get {
if (TabControl != null) {
return TabControl.SelectedContainer == TabItem;
}
return false;
}
}
}
Post adding this code inside my MainPage.Xaml.cs , I added a static constructor to register it
static MainWindow() {
NavigationAutomationPeersCreator.Default.RegisterObject(typeof(DXTabItem), typeof(DXTabItemAutomationPeerEx), owner => new DXTabItemAutomationPeerEx((DXTabItem)owner));
}
post this , these lines work as charm
TabItem CurrentTab = ViewsTabControl.SelectedTabItem as TabItem;
var Children = ViewsTabControl.FindAllChildren();
foreach (var child in Children) {
var subChildren = child.FindAllChildren();
}

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll?

Hi guys i am facing an exception in the following code,this code was working fine but i dont understand what happened to it now:
Exception is :
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Provide value on 'System.Windows.StaticResourceExtension' threw an exception.
<UserControl x:Class="AFIC.View.WirelessConfigurationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:AFIC.Resources"
xmlns:view="clr-namespace:AFIC.View"
xmlns:viewmodel="clr-namespace:AFIC.ViewModel"
>
<UserControl.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Height" Value="30"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<ContentPresenter
x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="400" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" Margin="0,10">
<StackPanel Height="550" Orientation="Vertical" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="65"/>
<ColumnDefinition Width="205"/>
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.ColumnSpan="1"
HorizontalAlignment="Left"
Content="IP Configuration:"
Foreground="Black"
FontWeight="ExtraBold"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Content="Wireless IP Address"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Column="1"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP1,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP2,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="2"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP3,UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="1"
Grid.Column="4"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding WirelessIP4,UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
<Label
Grid.Row="2"
Grid.ColumnSpan="1"
HorizontalAlignment="Left"
Content="AP Group Configuration"
Foreground="Black"
FontWeight="ExtraBold"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Content="Group ID"
Foreground="Black"
Opacity="0.8"
Margin="0,0,0,5"
/>
<TextBox
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Margin="0,0,0,5"
Text="{Binding GroupId,UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="3"
Grid.Column="2"
VerticalAlignment="Center"
Content="(1-1024)"
Foreground="Black"
Opacity="0.8"
Margin="0,0,0,5"
/>
<Label
Grid.Row="4"
Grid.Column="0"
VerticalAlignment="Center"
Content="AP Hardware Type"
Foreground="Black"
Opacity="0.8"
/>
<ComboBox
Grid.Row="4"
Grid.Column="1"
ItemsSource="{Binding AvailableHwTypes}"
SelectedItem="{Binding SelectedApHardwareType}"
>
</ComboBox>
<Button
Grid.Row="4"
Grid.Column="2"
Margin="10,0,0,0"
Command=""
Style="{StaticResource AddHwType}">
Add
</Button>
<Button
Grid.Row="6"
Grid.Column="3"
Margin="10,0,0,0"
Style="{StaticResource AppButtons}"
Command="{Binding ConfigWireless}">
Configuration
</Button>
<TextBox
Grid.Row="5"
Grid.ColumnSpan="3"
IsReadOnly="True"
IsEnabled="False"
Visibility="Hidden"
Height="10"/>
<DataGrid
Grid.Row="6"
Grid.ColumnSpan="3"
Height="100"
AutoGenerateColumns="False"
ItemsSource="{Binding wirelessconfiguration}"
SelectedValue="{Binding SelectedWireless}"
Name="dg"
>
<DataGrid.Columns>
<DataGridTextColumn Width="100" Header="S.No" Binding="{Binding Path=S_No}"/>
<DataGridTextColumn Width="100" Header="Group ID" Binding="{Binding Path=_groupId}"/>
<DataGridTextColumn Width="200" Header="AP Hardware Type" Binding="{Binding Path=_apHardwareType}"/>
</DataGrid.Columns>
</DataGrid>
<Label
Grid.Row="7"
Grid.Column="0"
HorizontalAlignment="Left"
Content="Network Configuration"
FontWeight="ExtraBold"
Foreground="Black"
FontSize="14"
Opacity="0.8"
/>
<Label
Grid.Row="8"
Grid.Column="0"
VerticalAlignment="Center"
Content="SSID"
Foreground="Black"
Opacity="0.8"
/>
<TextBox
Grid.Row="8"
Grid.Column="1"
VerticalAlignment="Center"
Text="Guest Network"
/>
<Label
Grid.Row="9"
Grid.Column="0"
VerticalAlignment="Center"
Content="Security"
Foreground="Black"
Opacity="0.8"
/>
<ComboBox
Margin="0,5,0,8"
Grid.Row="9"
Grid.Column="1"
ItemsSource="{Binding ACAvailableSecurityTypes}"
SelectedItem="{Binding ACSelectedSecurityType}"
>
</ComboBox>
<view:ACSecurityStaticWEP
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACStaticWep, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypeWepIEEE
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWEPIEEE, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypeWPAUC
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWPAPersonal, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<view:ACSecurityTypEnterprise
Grid.Row="11"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding IsACWPAEnterprise, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
Can anyone tell me where is the problem.Any help would be highly appreciable.
It seems that one of the StaticResources used does not exist:
Either:
AddHwType (Button Style)
AppButtons (Button Style)
BooleanToVisibilityConverter (Converter)
You might miss a merged dictionary somewhere or forgot to add a resource before using it. Review the XAML Resources page on MSDN for more info.
Solved:I was using wrong Static Resource i was writingStyle="{StaticResource AddHwType }" and it should be Style="{StaticResource AppButtons}" :)

Red border remains on the TextBox even after the data input is valid

I am writing an app using WPF, WPF Application Framework and MahApps.Metro. I have validation enabled for a data entry window like this:
<controls:MetroWindow x:Class="FinancePlus.Presentations.Views.CustomerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="526"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:presentation="clr-namespace:System.Waf.Presentation;assembly=WpfApplicationFramework"
presentation:ValidationHelper.IsEnabled="true" presentation:ValidationHelper.IsValid="{Binding IsValid, Mode=OneWayToSource}"
Title="Customer Editor">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Green.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid DataContext="{Binding Customer}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.Resources>
<Style TargetType="GroupBox">
<Setter Property="Margin" Value="10,5"></Setter>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<GroupBox Header="Personal Information" DockPanel.Dock="Top">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Title:" Grid.Column="0" Grid.Row="0" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="0" Height="23" Margin="3" Name="titleTextBox"
Text="{Binding Path=Title, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}"
VerticalAlignment="Center" MinWidth="120" />
<Label Content="Full Name:" Grid.Column="0" Grid.Row="1" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" Margin="3" Name="fullNameTextBox"
Text="{Binding Path=FullName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}"
VerticalAlignment="Center" MinWidth="120" />
<Label Content="Name With Initials:" Grid.Column="0" Grid.Row="2" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" Margin="4" Name="nameWithInitialsTextBox"
Text="{Binding Path=NameWithInitials, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}"
VerticalAlignment="Center" MinWidth="120" />
<Label Content="Civil Status:" Grid.Column="0" Grid.Row="3" Margin="3" VerticalAlignment="Center" />
<ComboBox DisplayMemberPath="CivilStatus" Grid.Column="1" Grid.Row="3" Height="23"
ItemsSource="{Binding}" Margin="3" Name="civilStatusComboBox" VerticalAlignment="Center" MinWidth="120" HorizontalAlignment="Stretch">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<Label Content="Date Of Birth:" Grid.Column="0" Grid.Row="4" Margin="3" VerticalAlignment="Center" />
<DatePicker Grid.Column="1" Grid.Row="4" Height="25" Margin="3" Name="dateOfBirthDatePicker" HorizontalAlignment="Right"
SelectedDate="{Binding Path=DateOfBirth, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="115" />
<Label Content="Id Number:" Grid.Column="0" Grid.Row="5" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="5" Height="23" Margin="3" Name="idNumberTextBox"
Text="{Binding Path=IdNumber, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}"
VerticalAlignment="Center" MinWidth="120" />
<Label Content="Profession:" Grid.Column="0" Grid.Row="6" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="6" Height="23" Margin="3" Name="professionTextBox"
Text="{Binding Path=Profession, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}"
VerticalAlignment="Center" MinWidth="120" />
</Grid>
</GroupBox>
..... More code.
The result looks like this:
Which looks nice. The trouble is even when I enter valid values for a TextBox a red border remains. Like you can see in the title and full name TextBoxes here. How do I remove this residue red border? Where is it coming from?
I've come across this before, when it happened to me I had to perform a data change during initialize and ContentRendered. Cause I had the items actually bound.
Another thing I saw awhile ago on Stack Overflow was an issue that happened here that also caused something similar.
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<ControlTemplate.Resources>
<BooleanToVisibilityConverter x:Key="converter" />
</ControlTemplate.Resources>
<DockPanel LastChildFill="True">
<Border
BorderThickness="1"
BorderBrush="Red"
Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource converter}}">
<AdornedElementPlaceholder x:Name="placeholder" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
That was my encounter, if that doesn't help I'll attempt to recreate the issue and fix as well. See if I can help you out a little better then describing how I fixed it. But hopefully one of those two suggestions helps you out.
Just let me know, hope it helps.

Reusable DataTemplate. How to specify? Need syntax assistance

This is my control with my custom DataTemplateSelector:
<m:Map x:Name="MainMap">
<m:MapItemsControl
ItemsSource="{Binding Source={StaticResource WorkLayerData}}">
<m:MapItemsControl.ItemTemplate>
<DataTemplate>
<Mobile:DevicePushpinTemplateSelector
m:MapLayer.Position="{Binding Location}"
ZoomLevel="{Binding ZoomLevel, ElementName=MainMap}"
Content="{Binding}">
<Mobile:DevicePushpinTemplateSelector.DotTemplate>
<DataTemplate>
<Ellipse Width="8" Height="8" Stroke="Black" Fill="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" StrokeThickness="1" />
</DataTemplate>
</Mobile:DevicePushpinTemplateSelector.DotTemplate>
<Mobile:DevicePushpinTemplateSelector.NumberedTemplate>
<DataTemplate>
<Border x:Name="border" Background="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" BorderBrush="Black" BorderThickness="2" Padding="2" Height="20" CornerRadius="8">
<TextBlock VerticalAlignment="Center" Text="{Binding DisplayId}" />
</Border>
</DataTemplate>
</Mobile:DevicePushpinTemplateSelector.NumberedTemplate>
<Mobile:DevicePushpinTemplateSelector.DetailedTemplate>
<DataTemplate>
<Border Background="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" BorderBrush="Black" BorderThickness="1" Padding="2" CornerRadius="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Id:" FontWeight="Bold" />
<TextBlock Text="{Binding DisplayId}" Grid.Column="1" />
<TextBlock Text="Device Id:" FontWeight="Bold" Grid.Row="1" />
<TextBlock Text="{Binding DeviceId}" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Speed:" FontWeight="Bold" Grid.Row="2" />
<TextBlock Text="{Binding Speed}" Grid.Row="2" Grid.Column="1" />
<TextBlock Text="Location:" FontWeight="Bold" Grid.Row="3" />
<TextBlock Text="{Binding Location}" Grid.Row="3" Grid.Column="1" />
<Button Content="View Details" Grid.Row="4" Grid.ColumnSpan="2" />
</Grid>
</Border>
</DataTemplate>
</Mobile:DevicePushpinTemplateSelector.DetailedTemplate>
</Mobile:DevicePushpinTemplateSelector>
</DataTemplate>
</m:MapItemsControl.ItemTemplate>
</m:MapItemsControl>
</m:Map>
I want to move my Mobile:DevicePushpinTemplateSelector.DetailedTemplate into resources so I can reuse it somewhere else.
I declared resource:
<UserControl.Resources>
<DataTemplate x:Key="DetailedMapItemTemplate">
<Border Background="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" BorderBrush="Black" BorderThickness="1" Padding="2" CornerRadius="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Id:" FontWeight="Bold" />
<TextBlock Text="{Binding DisplayId}" Grid.Column="1" />
<TextBlock Text="Device Id:" FontWeight="Bold" Grid.Row="1" />
<TextBlock Text="{Binding DeviceId}" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Speed:" FontWeight="Bold" Grid.Row="2" />
<TextBlock Text="{Binding Speed}" Grid.Row="2" Grid.Column="1" />
<TextBlock Text="Location:" FontWeight="Bold" Grid.Row="3" />
<TextBlock Text="{Binding Location}" Grid.Row="3" Grid.Column="1" />
<Button Content="View Details" Grid.Row="4" Grid.ColumnSpan="2" />
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
My problem is that I don't know HOW to use this DataTemplate inside my selector. What is the XAML I need to use? With controls like ListBox it is easy, just set ItemTemplate="{StaticResource thisTemplate}" but how do I do this in my case? Still learning XAML
Just set the DetailedTemplate property in the tag itself:
<Mobile:DevicePushpinTemplateSelector
m:MapLayer.Position="{Binding Location}"
ZoomLevel="{Binding ZoomLevel, ElementName=MainMap}"
Content="{Binding}"
DetailedTemplate="{StaticResource DetailedMapItemTemplate}">
...

Categories

Resources