将 ExpressionTextBox 的 ExpressionType 设置为泛型类型 [英] Setting ExpressionTextBox's ExpressionType to a generic type

查看:22
本文介绍了将 ExpressionTextBox 的 ExpressionType 设置为泛型类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设计器中为我的活动使用 ExpressionTextBox 控件时遇到了一个小问题.如何将 XAML 中的 ExpressionType 属性设置为定义 IEnumerable`1 泛型的 Type 对象?我可以完全不设置它,但理想情况下,我希望在设计时通过此控件获得验证支持.

I'm having a slight problem using the ExpressionTextBox control in a designer for an activity that I have. How does one go about setting its ExpressionType property in XAML to a Type object that defines the IEnumerable`1 generic? I can get away with not setting it at all, but ideally I'd like to get validation support at design time for the control with this.

我尝试了以下方法,但不起作用:

I've tried the following, which doesn't work:

<View:ExpressionTextBox 
   VerticalContentAlignment="Center" 
   Expression="{Binding Path=ModelItem.SelectedDestinations, Converter={StaticResource ResourceKey=ArgumentToExpressionConverter}, ConverterParameter=Out}" 
   ExpressionType="{x:Type TypeName=Generic:IEnumerable[Communication:CommunicationDeliveryDestination]}" 
   OwnerActivity="{Binding Path=ModelItem}" />

有关如何在 XAML 中正确设置 ExpressionType 属性的任何想法?以下是我的活动设计器的完整 XAML.

Any ideas in how to properly set the ExpressionType property in XAML? Below is the full XAML of the designer for my activity.

<sap:ActivityDesigner x:Class="UrbanScience.ELS.Orchestration.Activities.Design.SelectDestinationsByLeadDestinationTypeDesigner"
    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:View="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"
    xmlns:Generic="clr-namespace:System.Collections.Generic;assembly=mscorlib"
                      xmlns:System="clr-namespace:System;assembly=mscorlib">

    <sap:ActivityDesigner.Resources>
        <ResourceDictionary>
            <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
        </ResourceDictionary>
    </sap:ActivityDesigner.Resources>

    <Grid Height="50">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" />
            <ColumnDefinition MinWidth="200" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Lead Destination Type:" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" />
        <ComboBox Name="LeadDestinationTypeItems" VerticalAlignment="Center" SelectedIndex="0" Grid.Row="0" Grid.Column="1" SelectionChanged="OnLeadDestinationTypeChanged" />

        <TextBlock Text="Assign selected destinations to:" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" />
        <View:ExpressionTextBox VerticalContentAlignment="Center" 
                                Expression="{Binding Path=ModelItem.SelectedDestinations, Converter={StaticResource ResourceKey=ArgumentToExpressionConverter}, ConverterParameter=Out}"
                                ExpressionType="{x:Type TypeName=Generic:IEnumerable[Communication:CommunicationDeliveryDestination]}"
                                OwnerActivity="{Binding Path=ModelItem}" Grid.Row="1" Grid.Column="1">
        </View:ExpressionTextBox>
    </Grid>
</sap:ActivityDesigner>

推荐答案

使用 ModelItem 获取属性类型并绑定到它,像这样:

Use ModelItem to get property type and bind to it, like this:

ExpressionType={Binding ModelItem.Properties[SelectedDestinations].PropertyType.GenericTypeArguments[0]}

这篇关于将 ExpressionTextBox 的 ExpressionType 设置为泛型类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆