No buttons on dialog

Mar 5, 2012 at 3:17 PM

Hi,

I have another - beginner - question.

I have created a window that I want to show as a dialog:

<catel:DataWindow x:Class="TestCatel.Presentation.WPF.View.IngredientListWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
				  xmlns:catel="http://catel.codeplex.com"
                  xmlns:ViewModel="clr-namespace:TestCatel.Control.WPF.ViewModel;assembly=TestCatel.Control.WPF"
                  xmlns:LocalControl="clr-namespace:TestCatel.Presentation.WPF.View"
                  x:TypeArguments="ViewModel:IngredientListViewModel"
                  ResizeMode="CanResize">
    <!-- Resources -->
    <catel:DataWindow.Resources>
       
    </catel:DataWindow.Resources>
 
    <ListView ItemsSource="{Binding IngredientList}">
 
        <ListView.View>
 
            <GridView AllowsColumnReorder="true" >
 
                <GridViewColumn DisplayMemberBinding="{Binding Path=Name}" Header="Ingredient" Width="Auto"/>
                <GridViewColumn Header="Danger" Width="Auto">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Text="{Binding Path=DangerClass}" Style="{StaticResource ListViewUnSelected}"/>
                                <TextBox Text="{Binding Path=DangerClass, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" Style="{StaticResource ListViewSelected}" />
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
 
            </GridView>
 
        </ListView.View>
    </ListView>
</catel:DataWindow>

public class IngredientListViewModel : ViewModelBase

I call it this way:

var viewModel = new IngredientListViewModel();
var uiVisualizerService = GetService<IUIVisualizerService>();
uiVisualizerService.ShowDialog(viewModel);
But no buttons (OK, Cancel) are displayed. I thought that they would be added automatically. I checked the example application Catel.Examples.WPF.Validation but I fail to find the place where the OK and Cancel button are added.

thanks, Gorroux

Coordinator
Mar 5, 2012 at 6:56 PM

The OK and Cancel buttons are added by the DataWindow itself. However, you can customize this in the constructor of the view. Can you show me the code-behind for IngredientListWindow?

Also, you might be interested in the latest beta, it no longer requires generic base classes for the views :)

Thanks in advance!

Mar 6, 2012 at 8:54 AM

I'm trying to convert my test application to 3.0 right now.

As I use another project for the viewmodels I need to add a naming convention:

var viewModelLocator = ServiceLocator.Instance.ResolveType<IViewModelLocator>();
viewModelLocator.NamingConventions.Clear();
viewModelLocator.NamingConventions.Add("TestCatel.Control.WPF.ViewModels.[VW]ViewModel");

But where do I have to put this code? If in MainWindow constructor it is to late - the framework cannot find the viewmodel. If I put in in the App.xaml codebehind I get the following error message:

The type 'Catel.MVVM.IViewModelLocator' is not registered, not even in an external container

Also, is it correct, that the Datawindow is now also non-generic?

THANKS, Gx

Coordinator
Mar 6, 2012 at 8:58 AM

Mainly in the app startup. However, the services are registered by default by the first ViewModelBase creation. Thus, if you want to use it earlier, you can do something like this:

var serviceLocator = ServiceLocator.Instance;

serviceLocator.RegisterType<IViewModelLocator, ViewModelLocator>();

var viewModelLocator = serviceLocator.ResolveType<IViewModelLocator>();
viewModelLocator.NamingConventions.Add("TestCatel.Control.WPF.ViewModels.[VW]ViewModel");

All views are now available as non-generic, thus the DataWindow, UserControl, Page and PhoneApplicationPage are all available as non-generic now (but the generics are still there for backward compatibility).

See this documentation for all options regarding the ViewModelLocator:

http://catel.catenalogic.com/3.0-beta/index.html?mvvm_locators_viewmodellocator.htm

Coordinator
Mar 6, 2012 at 9:00 AM

btw, tonight we will release an official beta including the templates, docs, etc. Both via nuget and an official beta installer.

Mar 6, 2012 at 9:30 AM

The buttons now work fine, I did indeed miss the point.

I can now access the viewModel locator, but it still does not work. Also the viewLocator does not work opening a new model.

If I register the view explicitly and using the GetViewModelType() overloads everything works fine.

I will attach my project to the IsDirty issue. Maybe you can have a look at this topic as well.

Thanks, Gorroux

Mar 6, 2012 at 9:47 AM

On more little suggestion about the naming conventions for the locators: I "had" a UserControl called "ReceiptUserControl". So the postfix was non of your defined postfixes (should be named ReceiptControl), so the automatic resolve could not work.

You could let the user add a list of known postfixes to the locators next to the naming conventions.

Gx

Coordinator
Mar 6, 2012 at 9:50 AM

Hmmm, interesting. I will add UserControl to the list.

Mar 6, 2012 at 9:52 AM

It's really all about habit, isn't it :)

Coordinator
Mar 6, 2012 at 9:54 AM

Yes, we used to write the UI like this:

UI/Controls/MyControl
UI/Windows/MyWindow 

etc, but now we put everything into the Views folder, seems easier to understand for most people. But, luckily we support most used naming conventions (and allow several naming conventions to be used together at once). The beta we will release tonight will contain the UserControl postfix fix.

Mar 6, 2012 at 9:56 AM

Great.

I believe Catel will by indeed my choice for the next big project coming on. Support is great. Thanks!