1

I hope you can help me with my problem. It's about a custom designer for a WF 4.0 activity, but the problem is essentially in the WPF of the designer. Some background

I've created a custom WorkFlow activity to send e-mails. For the custom designer for the activity, I've previously been using regular Textboxes for the "Subject" and "Body" of the e-mail, but I'd like to use the ExpressionTextBox to easily bind it to the InArguments of the activity. The ExpressionTextBoxes are in a grid, and this grid is on a StackPanel.

I've set the the MinWidth, MaxWidth and Margin of the ExpressionTextBoxes to fit with the other controls, and in the Visual Studio Designer (viewing the custom activity designer, not the actual WorkFlow) everything looks as it should.

<sapv:ExpressionTextBox Grid.Column="1" Grid.Row="2" Height="Auto" HorizontalAlignment="Right" Margin="4, 4, 4, 4" 
                        Expression="{Binding Path=ModelItem.Subject, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
                        ExpressionType="{x:Type TypeName=sys:String}" OwnerActivity="{Binding Path=ModelItem}" VerticalAlignment="Center" MaxWidth="176" MinWidth="175" />

The problem

When used, initially it also looks as it should, but when the ExpressionTextBoxes are edited, they shrink into being really small. When text is entered, the control expands to fit the text, until it reaches its MaxWidth. When the editing ends, it goes back to it's MaxWidth. I'd prefer if it stayed the same size, regardless of being in edit-mode or not.

Small demonstration of the problem.

If you can't see it, open the image here

What I've tried

I've mostly been doing WinForms, and I'm pretty inexperienced with WPF, so I don't know if there are some funky properties or other settings that I've missed. I've tried setting width-properties of the parent controls (StackPanel and Grid), I've tried setting just the width (no min/max), but it seems to shrink regardless of what I set.

If you would like more information or code, please don't hesitate to ask.

Update

As you can see in the comments to Maurices answer, I figured out how to avoid the problem by removing the horizontalAlignment property, and then using margins to align it to the right. But I'm not going to mark an answer, until there's an explanation of why this behaviour happened in the first place. My XAML was almost identical to what Maurice posted, so there must be something wrong elsewhere.

Lars Kristensen
  • 1,410
  • 19
  • 29

1 Answers1

0

The XAML for the ExpressionTextBox looks fine to me and when I try the following designer it works just fine.

<sap:ActivityDesigner x:Class="WorkflowConsoleApplication2.MyActivityDesigner"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:sys="clr-namespace:System;assembly=mscorlib"
                      xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
                      xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
                      xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation">
  <sap:ActivityDesigner.Resources>
    <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
  </sap:ActivityDesigner.Resources>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="30"/>
      <RowDefinition Height="30"/>
      <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Label Content="Subject"
           Grid.Row="2"
           Grid.Column="0"/>
    <sapv:ExpressionTextBox Grid.Column="1"
                            Grid.Row="2"
                            Height="Auto"
                            HorizontalAlignment="Right"
                            Margin="4, 4, 4, 4"
                            Expression="{Binding Path=ModelItem.Subject, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
                            ExpressionType="{x:Type TypeName=sys:String}"
                            OwnerActivity="{Binding Path=ModelItem}"
                            VerticalAlignment="Center"
                            MaxWidth="176"
                            MinWidth="175" />
  </Grid>
</sap:ActivityDesigner>

So I suspect the problem is possibly in your grid definition.

Maurice
  • 27,582
  • 5
  • 49
  • 62
  • For the column containing the ExpressionTextBoxes, the width was set to "Auto". I've tried setting it to "*" or a fixed value, and while this has an effect on the grid itself, the ExpressionTextBoxes still shrink when being edited. – Lars Kristensen Aug 09 '11 at 12:12
  • @LarsKristensen: Have you tried setting the `Width` of the ETB? –  Aug 09 '11 at 12:49
  • I've tried setting the Width, but it didn't do the trick either. I discovered that if I removed the HorizontalAlignment="Right" property, the problem went away. Actually, if I set the HorizontalAlignement to anything other than "Stretch", it would do the shrinking. But I want my ETB (and everything else in that column) to be aligned to the left. Is there a way to do this without setting it directly on the control, or do I have to fine-tune the Margin property to fit with the other controls? (I have several other ETB's in the collapsed "Optional settigns") – Lars Kristensen Aug 09 '11 at 13:17
  • I don't know if it makes a difference, but the activities with their designers are used in a re-hosted WorkFlow designer. Could any settings or properties in this WF Designer have an influence on my Activity Designer? (The re-hosted WF designer was not developed by me, but I can access the project if necessary) – Lars Kristensen Aug 09 '11 at 13:23