如何将表单代码活动绑定到XAML?

时间:2011-12-10 10:34:29

标签: c# xaml binding android-activity workflow-activity

我正在尝试创建一个活动设计器库。我有两个来源;其中一个是C#代码中的CodeActivity,另一个是XAML中的Activity designer。在CodeActivity中,我有一个公共财产Name。在XAML中,我想通过绑定来查看和更改它的值。 My XAML design is like this

我声明Name属性如下:

private string _name;
public string Name { 
    get { return _name; } 
    set 
    { 
        _name = value;
        NotifyPropertyChanged("Name");
    } 
}

public event PropertyChangedEventHandler PropertyChanged;

public void NotifyPropertyChanged(string propertyName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this,
            new PropertyChangedEventArgs(propertyName));
    }
}

我的XAML是这样的:

...    
<DataTemplate x:Key="Expanded">
    <StackPanel>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40"/>
                <ColumnDefinition Width="130"/>
            </Grid.ColumnDefinitions>

            <TextBox x:Name="txtName" Grid.Column="1" Grid.Row="0" Text="{Binding Name, Mode=TwoWay}"/>
            <TextBlock Grid.Column="0" Grid.Row="0" Text="Name :" HorizontalAlignment="Right"/>
        </Grid>
        <sap:WorkflowItemPresenter Item="{Binding Path=ModelItem.Body, Mode=TwoWay}"
                            HintText="Please drop an activity here" />
    </StackPanel>
</DataTemplate>

我尝试了很多方法,但我无法做到。 如何在XAML中显示Name的{​​{1}}属性?

1 个答案:

答案 0 :(得分:1)

我明白了。 当我们想要将CodeActivity Side中的变量绑定到XAML时,我们会这样做:

...
xmlns:s="clr-namespace:System;assembly=mscorlib"
<sap:ActivityDesigner.Resources>
    <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" /> 
...
<sapv:ExpressionTextBox HintText="Enter custom text here ..." Expression="{Binding Path=ModelItem.Text, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}" ExpressionType="s:String" OwnerActivity="{Binding Path=ModelItem}" MaxLines="1"/>
...