问题
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}" />
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>
回答1:
Use ModelItem
to get property type and bind to it, like this:
ExpressionType={Binding ModelItem.Properties[SelectedDestinations].PropertyType.GenericTypeArguments[0]}
来源:https://stackoverflow.com/questions/15393616/setting-expressiontextboxs-expressiontype-to-a-generic-type