views:

60

answers:

1

Blend supports displaying the graphical representation of a style resource, and allows you to select an active property/event trigger to view or modify. However, it's a common occurrence to have visual elements controlled by DataTriggers. Is it possible to tell the designer that it should consider a DataTrigger 'active' so that its visual changes can be viewed in the designer?

Example:

<Style x:Key="MyBorder" TargetType="Border">
    <Setter Property="CornerRadius" Value="5" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsRandomPropertyActive}" Value="True">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Color="#FFFF8935" Offset="0" />
                        <GradientStop Color="#FFFF610C" Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>

In the designer, this simply displays an empty box as the default style defines no specific visual aspects. Is there anyway to tell the designer that I want it to assume IsRandomPropertyActive is true, and display the appropriate styling?

+1  A: 

If you are using mock ViewModels with Blend, a nice trick is to load your design-time ViewModels from a separate XAML file in the project. If you do this you can easily change the XAML inside Blend and immediately see the changes take effect. For example, you would change your XAML for the mock ViewModel to say:

<AViewModelObject>
  ...
  <AnotherViewModelObject ... IsRandomPropertyActive="true" ... />
  ...
</AViewModelObject>

I am not aware of any simpler way to achieve the functionality you desire.

Ray Burns
Thanks, I guess this is the only way to get around the issue at the moment. Not sure if this will suit the specific situation but I'll give it a try
jeffora
Good idea ... wish Blend supported the use of DataTriggers ... I honestly do not understand why Blend v3 or Blend v4 does not at this point.
cplotts