locked
How can I parse the selection of a ComboBox to a ExpressionTextBox? RRS feed

  • Question

  • Hello, I'm a freshman of WF 4.0. And now I'm trying to write some custom activities. I want to parse a combobox's selection(a string) to a ExpressionTextBox instead of typing it into ExpressionTextBox. But I don't know how to do it. Can anyone help me? Here is my designer:
    <sap:ActivityDesigner x:Class="FDActivityLibrary.FaultFactActivityDesigner"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        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"
        xmlns:s="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="89" d:DesignWidth="201"
        xmlns:c="clr-namespace:FDActivityLibrary">
        <sap:ActivityDesigner.Resources>
            <c:EmployeeArr x:Key="EmpCols"/>
            <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter"/>
            <DataTemplate x:Key="Collapsed">
                <StackPanel>
                    <TextBlock>This is the collapsed view</TextBlock>
                    
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="Expanded">
                <StackPanel>
                    <ComboBox x:Name="cmb"
                              Margin="8,8,8,7.04"
                              ItemsSource="{StaticResource EmpCols}"
                              DisplayMemberPath="Name"
                              SelectedValuePath="EmpID"
                              SelectionChanged="cmb_SelectionChanged" />
                    <TextBlock Grid.Row="1"
                               VerticalAlignment="Center"
                               FontSize="18"
                               HorizontalAlignment="Center"
                               Text="{Binding ElementName=cmb,Path=SelectedValue}" />
                                    
                    <Label Content="I want to parse the selectedvalue to the one below :"></Label>
                    <sapv:ExpressionTextBox Name="factIdExpression" HintText="factId"
                          OwnerActivity="{Binding Path=ModelItem}"
                                            Expression="{Binding Path=ModelItem.factId,
                                               Mode=TwoWay,                                           
    Converter={StaticResource ArgumentToExpressionConverter },
                                               ConverterParameter=In}"                                           
    ExpressionType="s:String"/>
                   
                    
                </StackPanel>
            </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>

    Friday, March 16, 2012 6:45 AM

Answers

  • You can use SelectionChanged, or you can use WPF binding + converters.

    Going with the SelectionChanged approach, you would programmatically need to set the 'ExpresssionText' property of the ExpressionTextBox, or alternatively to update the model property the expression text box is bound to.

    Going with the SelectionChanged approach has the downside that handling global Undo, Redo is a bit tricky.

    If possible I'd recommend using WPF binding approach instead, by binding the combo box to the same model property which you bind the expression text box to. You need an appropriate two-way IValueConverter to convert between types that model item can handle, and your combo box or list box can handle.
    Tim

    Wednesday, March 28, 2012 7:18 AM

All replies

  • Here is my custom activity in designer. What I want is pass the selection of the combobox to the "factId" ExpressionTextBox below, and save it in xaml just as that I type a expression into "factId" ExpressionTextBox. Shall I use the SelectionChanged method? How to pass the value? Thanks!
    Friday, March 16, 2012 7:32 AM
  • You can use SelectionChanged, or you can use WPF binding + converters.

    Going with the SelectionChanged approach, you would programmatically need to set the 'ExpresssionText' property of the ExpressionTextBox, or alternatively to update the model property the expression text box is bound to.

    Going with the SelectionChanged approach has the downside that handling global Undo, Redo is a bit tricky.

    If possible I'd recommend using WPF binding approach instead, by binding the combo box to the same model property which you bind the expression text box to. You need an appropriate two-way IValueConverter to convert between types that model item can handle, and your combo box or list box can handle.
    Tim

    Wednesday, March 28, 2012 7:18 AM
  • Thanks for your reply,Tim:)
    Tuesday, May 22, 2012 8:49 AM
  • Leehawk, do you mind to post your solution code here ?
    Thursday, April 17, 2014 8:30 AM