views:

18

answers:

2

I've got a simple window, that is container for various views. I've got a DataTemplate that shows the correct view based on whatever the window's MainViewModel property is set to.

<DataTemplate DataType="{x:Type VM:StartupViewModel}">
    <AdornerDecorator>
        <V:StartupView />
    </AdornerDecorator>
</DataTemplate>

What I'd like to do is for certain views, change some properties on the base window, ie WindowStyle, ResizeMode etc. something like triggers, but on datatypes instead of property values? How could I accomplish this?

edit:

After a bit more googling I think I want to do something like this:

<Window.Style>
        <Style>
            <Setter Property="Window.WindowStyle"
                    Value="SingleBorderWindow" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self} , Path=DataContext.MainViewModel}"
                             Value="{x:Type VM:StartupViewModel}">
                    <Setter Property="Window.WindowStyle"
                            Value="None" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Style>

This rums, but has no effect...

A: 

I'm not sure you can bind directly to the datatype. But you can set some property in the ViewModel according to the datatype selected. In turn you can bind your WindowStyle Property to this property.

If you're able to bind to the DataType somehow, you can use BindingConverters and bind directly to window properties.

Veer
A: 

OK, after much frustration I figured out why it wasn't working. The binding path was returning the correct object, but since the Value is an x:Type, it seems to be comparing an instance object vs a type. So I added a simple converter that returns the Type of an object, and it worked.

I had assumed that if I specified my value as x:Type, WPF would know I wanted to compare the type of the binding to the value. For a long while I figured that binding was fine, and the problem was with the trigger, which as far as I could see should have worked. Was starting to think something was wrong with visual studio ;D

Kage