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

发布于 2024-12-20 16:08:12 字数 1710 浏览 1 评论 0原文

我正在尝试制作一个活动设计师库。我有两个来源;其中之一是 C# 代码中的 CodeActivity,另一个是 XAML 中的活动设计器。在 CodeActivity 中,我有一个公共属性 Name。在XAML中,我想通过绑定来查看和更改它的值。 我的XAML设计是这样的

我声明了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 中显示 CodeActivity 中的 Name 属性?

I'm trying to make an activity designer library. I have two sources; one of them is CodeActivity in C# code and the other one is Activity designer in XAML. In CodeActivity, I have a public property Name. In XAML, I want to view and change it's value through binding. My XAML design is like this

I declared Name property like this:

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));
    }
}

And my XAML is like this:

...    
<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>

I've tried a lot of ways, but I couldn't do it.
How can I show the Name property from CodeActivity in XAML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-12-27 16:08:12

我得到了它。
当我们想要将 CodeActivity 端的变量绑定到 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"/>
...

I got it.
When we want to bind a variable from CodeActivity Side to XAML, we do like this :

...
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"/>
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文