Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:45:13+00:00 2026-06-05T13:45:13+00:00

Using MVVM. I have a DataTemplate which I am using to display an expander

  • 0

Using MVVM. I have a DataTemplate which I am using to display an expander with some controls in per object.

<DataTemplate>
    <Expander ExpandDirection="Down" IsExpanded="False">
        <Expander.Header>
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="Platform Group {0} {1}">
                        <Binding Path="PlatformGroupCode"/>
                        <Binding Path="PlatformGroupName"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </Expander.Header>
        <vw:PlatformGroup HorizontalAlignment="Left"/>
    </Expander>
</DataTemplate>

Inside that view is 2 textboxes bound to those 2 properties. I’m using IDataErrorInfo in my VM to do validation and I’ve a style in my main application resources to display error messages as tooltips:

<Style TargetType="{x:Type TextBox}">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors).CurrentItem.ErrorContent}"/>
        </Trigger>
    </Style.Triggers>
</Style>

When a new group is added the 2 properties have default values, which is invalid so I want the textboxes to be red to prompt the user to enter data. This works if the Expander’s IsExpanded is set to true. But if it is false I have to expand AND change the value in one of the textboxes in order to get the red border and tooltip to show.

I don’t want to set the expander to be expanded because there will eventually be quite a few controls. How can I get the red border to show as soon as the expander is expanded? Even better, is there a way to make the newly added expander expand (when user adds a new group I’m adding a PlatformGroupviewModel to an observablecollection of PlatformGroupviewModels)?

EDIT more detail:
the top level view:

 <StackPanel Orientation="Vertical">
        <ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="630">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="5*" />
                    <ColumnDefinition Width="5*" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Vertical" Grid.ColumnSpan="2" Grid.Row="1" HorizontalAlignment="Stretch">
                    <Expander ExpandDirection="Down" IsExpanded="True" Header="Header" HorizontalAlignment="Stretch" Name="expHeader" VerticalAlignment="Top">
                        <vw:Header DataContext="{Binding HeaderVM}"/>
                    </Expander>
                    <Expander ExpandDirection="Down" IsExpanded="True" Header="Platform Groups" HorizontalAlignment="Stretch" Name="expPlatformGroups" VerticalAlignment="Top">
                        <AdornerDecorator>
                            <vw:PlatformGroups DataContext="{Binding PlatformGroupsVM}"/>
                        </AdornerDecorator>
                    </Expander>
                </StackPanel>
            </Grid>
        </ScrollViewer>
</StackPanel>

the PlatformGroups view:

 <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="10,10,10,10">
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="0,10">
        <Label Content="Number of platform groups" VerticalAlignment="Center"/>
        <vw:IntegerInput MinValue="0" MaxValue="50" MaxLength="2"  Text="{Binding Path=NumPlatformGroups, Mode=TwoWay,ValidatesOnDataErrors=True}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
    </StackPanel>
    <ItemsControl IsTabStop="False" ItemsSource="{Binding PlatformGroups}" Margin="20,10" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Expander ExpandDirection="Down" IsExpanded="False">
                    <Expander.Header>
                        <TextBlock>
                            <TextBlock.Text>
                                <MultiBinding StringFormat="Platform Group {0} {1}">
                                    <Binding Path="PlatformGroupCode"/>
                                    <Binding Path="PlatformGroupName"/>
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </Expander.Header>
                    <AdornerDecorator>
                        <vw:PlatformGroup HorizontalAlignment="Left"/>
                    </AdornerDecorator>
                </Expander>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.Template>
            <ControlTemplate>
                <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}"
        BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                    <ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="400" CanContentScroll="True" Padding="{TemplateBinding Control.Padding}" Focusable="False">
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>
</StackPanel>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:45:15+00:00Added an answer on June 5, 2026 at 1:45 pm

    As per this post, wrapping your Expander content inside an AdornerDecorator should solve this problem –

    <DataTemplate>
        <Expander ExpandDirection="Down" IsExpanded="False">
            <Expander.Header>
               ...
            </Expander.Header>
    
            <AdornerDecorator>
                <vw:PlatformGroup HorizontalAlignment="Left"/>
            </AdornerDecorator>
    
        </Expander>
    </DataTemplate>
    

    Another SO thread which confirms this – Issue with WPF validation(IDataErrorInfo) and tab focusing

    Some other WorkArounds are also mentioned on this connect bug –

    TabControl doesn’t display Validation error information correctly when switching tabs back and forth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which I am trying to design using the MVVM pattern.
I'm new to WPF and using MVVM. I have a view in which I
I am using MVVM architecture. I have a usercontrol UC as a View Model
I'm using MVVM to bind views to objects in a Tree. I have a
I'm developing a WPF app using MVVM. Most of my views have only xaml
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I'm using MVVM in my WPF project. Now I want to display a subwindow
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model
I have been using ItemsControl for quiet sometime in WPF. I am using MVVM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.