views:

26

answers:

0

I have a custom control which is hosted in a Window with some other controls on it. The custom control and the window are in different assemblies as the custom control is to be shared across several applications. Within the window I define a style for type FrameworkElement and then in that style I set the ControlTemplate to utilize an AdornedElementPlaceholder paired with a TextBlock placed below it to highlight and message when a control has a validation error. Inside the custom control, one of several UI elements is a ListView that references this style via {DynamicResource {x:Type FrameworkElement}} since it's defined in a different assembly. When the UI element in the custom control has a validation error, the style is applied correctly, but the TextBlock below it is overlapping other controls that exist on the Window containing this custom control. The Window is using a grid and several StackPanel's to arrange layout and the Window is already set to SizeToContent for WidthAndHeight. The custom control is also set as the content for one of the StackPanels via a property in the Window code behind during runtime. Any assistance getting the Window elements to dynamically readjust their layout when the error template is applied would be great. Code snippets are attached below, if any other information is needed, please let me know. Thanks in advance.

The custom control in one assembly:

<UserControl x:Class="SettingsControl"
    Width="340" Height="Auto" Margin="0" Padding="5" Loaded="UserControl_Loaded">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="37*"/>
            <RowDefinition Height="73*"/>
        </Grid.RowDefinitions>
        <Grid Margin="5,5,5,5" Grid.Row="0">
            <DockPanel DockPanel.Dock="Bottom" LastChildFill="False" >
                <Button Name="BrowseButton" Command="{Binding Path=BrowseCommand, Mode=OneWay}" 
                        d:LayoutOverrides="HorizontalAlignment" LostFocus="BrowseButton_LostFocus" Content="{x:Static prop:Resources.SettingsControl_BrowseButtonCaption}" HorizontalAlignment="Center" 
                        HorizontalContentAlignment="Center" Width="65" DockPanel.Dock="Right" VerticalAlignment="Top" VerticalContentAlignment="Top" 
                        TabIndex="1" />
                <TextBlock VerticalAlignment="Bottom">
                    <Underline>Selected PDF's</Underline>
                </TextBlock>
            </DockPanel>
        </Grid>
        <Grid Margin="5,0,5,5" Grid.Row="1">
            <ListView TabIndex="0" Height="60" x:Name="FileNameListBox" d:LayoutOverrides="Height" VerticalAlignment="Stretch" VerticalContentAlignment="Center" 
                      HorizontalAlignment="Stretch" Style="{DynamicResource {x:Type FrameworkElement}}" >
                <ListView.ItemsSource>
                    <Binding Path="FileNames" Mode="OneWay" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True"/>
                </ListView.ItemsSource>
            </ListView>
        </Grid>
    </Grid>
</UserControl>

The Window that contains the custom control above:

<Window x:Class="InputSettingsOverride" Title="InputSettingsOverride" 
                SizeToContent="WidthAndHeight" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False" 
                WindowStyle="SingleBorderWindow" ContentRendered="Window_ContentRendered">
    <Window.Resources>
        <ResourceDictionary>
            <Style TargetType="FrameworkElement">
                <Setter Property="Validation.ErrorTemplate">
                    <Setter.Value>
                        <ControlTemplate>
                            <ControlTemplate.Resources>
                                <QuickScan:HeightToBottomMarginConverter x:Key="HeightToBottomMarginConverter" />
                            </ControlTemplate.Resources>
                            <StackPanel Name="MainPanel" >
                                <Border BorderBrush="Red" BorderThickness="1" >
                                    <AdornedElementPlaceholder Name="MyAdorner" />
                                </Border>
                                <TextBlock Name="ErrorTextBlock" Foreground="Red" Height="Auto" 
                                                   Text="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" 
                                                   FontFamily="Segoe UI,Tahoma" FontSize="12" Margin="0,3,0,0" Width="{Binding ElementName=MyAdorner, Path=ActualWidth}" 
                                                   TextWrapping="Wrap"/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" x:Name="SettingsHost" Orientation="Horizontal"/>
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10,0,10,5">
            <ComboBox x:Name="ClassificationOptionsList" DisplayMemberPath="TypeName" ItemsSource="{Binding Path=ViewModel.ClassificationOptions, Mode=OneWay}" 
                              SelectedValue="{Binding Path=ViewModel.ClassificationType, Mode=TwoWay}" />
        </StackPanel>
        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="10,5,10,5" HorizontalAlignment="Right" VerticalAlignment="Center">
            <Button x:Name="OkButton" Height="{Binding ElementName=CancelButton, Path=ActualHeight, Mode=OneWay}" 
                            Width="{Binding ElementName=CancelButton, Path=ActualWidth, Mode=OneWay}" IsDefault="True" Command="{Binding Path=Ok}" 
                            Content="O_K" IsCancel="False" />
            <Button x:Name="CancelButton" Margin="10,0,0,0" Padding="10,5,10,5" IsCancel="True" Content="_Cancel" 
                            PreviewGotKeyboardFocus="CancelButton_PreviewGotKeyboardFocus" PreviewLostKeyboardFocus="CancelButton_PreviewLostKeyboardFocus" 
                            Click="CancelButton_Click" />
        </StackPanel>
    </Grid>
</Window>