Search code examples
c#.networkflow-foundation-4workflow-foundation

Add an image to a windows workflow custom activity designer


I am developing some custom activities in Windows workflow using the designer to add some nice custom looks for users. I have been able to do everything like in WPF mostly although I am having an issue loading images in the actual workflow view. This is how it looks in the designer

enter image description here

<sap:ActivityDesigner.Resources>
    <DataTemplate x:Key="Collapsed">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MaxWidth="40"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Image MaxWidth="40" MaxHeight="20" Grid.Column="0" HorizontalAlignment="Left" Source="pack://application:,,,/Images/Web.ico"></Image>
            <Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Grid.Column="1">Collapsed View</Label>
        </Grid>
    </DataTemplate>
    <DataTemplate x:Key="Expanded">
     <Grid>
    <Label>hi</Label>
    </Grid>

    </DataTemplate>

    <Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}">
        <Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="true">
                <Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</sap:ActivityDesigner.Resources>
 <Grid>
    <ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}" />
</Grid>
</sap:ActivityDesigner>

But in Visual Studio 2015 when creating a workflow, it looks like this:

enter image description here


Solution

  • What I've found is that the image needs to include the namespace. The image tag should look similar to this:

    <Image MaxWidth="40" MaxHeight="20" Grid.Column="0" HorizontalAlignment="Left" 
           Source="pack://application:,,,/MyNamespace;component/Lookup.png"></Image>
    

    The Build Action for the Lookup.png should be "Resource".