Question

Applying any theme causes DataTemplate to fail

Posted 3 years ago by Avatar Ed Starkey

I have working code that pulls data from a ViewModel and then displays it in my View by means of a DataTemplate. Whenever I apply a Theme using ThemeManager, my DataTemplate Fails. I am just applying the Actipro supplied themes.

 

My XAML is nothing special

<docking:ToolWindow Title="Test" x:Name="testToolBar" Width="200">
                        <ListView Name="testListView" DataContext="{Binding Source={StaticResource TestTypeViewModelDataSource}}" ItemsSource="{Binding AvailableTest}" HorizontalContentAlignment="Stretch">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel HorizontalAlignment="Center" ToolTip="{Binding TestDescription}" Margin="0,5" Height="70">
                                        <Image Source="{Binding TestIcon}" Width="50" Stretch="UniformToFill"/>
                                        <Label Content="{Binding TestName}"/>                                        
                                    </StackPanel>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                        
                        
                    </docking:ToolWindow>

 In my App.xaml.cs code I have basic Theme assignment.

protected override void  OnStartup(StartupEventArgs e)
        {
 	        base.OnStartup(e);
           ThemeManager.BeginUpdate();

           try
           {
               ThemesOfficeThemeCatalogRegistrar.Register();
               ThemeManager.AreNativeThemesEnabled = true;

               ThemeManager.CurrentTheme = ThemeName.AeroNormalColor.ToString();
           }

           finally
           {
               ThemeManager.EndUpdate();   
           }


           

        }

 If I leave out the ThemeManager.EndUpdate(), My DataTemplate works fine.

Any suggestions?


Comments (2)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Ed,

If you can please put together a small sample project that reproduces your issue and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.


Actipro Software Support
Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Ed,

Thank you for the sample application. The issue here has to do with the fact that you have enabled our Native Themes support *and* you are using a ListView like a ListBox. The ListView derives from ListBox and adds a "view", of which there is currently only a GridView that can be used. Assuming you don't set the View property, your ListView is effectively nothing more than a ListBox. If you set the View property to a GridView, then you can specify columns etc.

Due to how the ListView specifies it's default themes, we had to make the decision of whether to style the ListView with or without the GridView (as it would not be possible to support both as the default styles do). We chose the former, because if you don't have a View you can use a ListBox instead and get the same resulting UI.

So in your case above, you can replace the ListView with a ListBox. Alternatively, you could specify a GridView with appropriate columns and it would work as well.


Actipro Software Support

Add a Comment

Please log in to a validated account to post comments.