我希望有人能幫助我。我很沮喪。Complex DataBinding
因此,這裏是我的問題:
我已經得到的屬性列表,這個屬性是控件的屬性。現在我必須在我的屬性網格和控制自己之間有約束力。我的控制模板看起來是這樣的:
<DataTemplate x:Key="LabelVisualObject" DataType="{x:Type ContentControl}">
<ContentControl Content="{Binding}" ContentTemplateSelector="{StaticResource LabelLayoutTemplateSelector}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Properties, Converter={StaticResource PropertyConverter}, ConverterParameter=VisualizationObjectTypeAttribute.Layout.Name}" Value="Layout_OneLine">
<Setter Property="ContentTemplate" Value="{StaticResource LabelOneLineVisualObject}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Properties, Converter={StaticResource PropertyConverter}, ConverterParameter=VisualizationObjectTypeAttribute.Layout.Name}" Value="Layout_TwoLines">
<Setter Property="ContentTemplate" Value="{StaticResource LabelTwoLinesVisualObject}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
PropertyConverter
[ValueConversion(typeof(IEnumerable<IPropertyEditorAttribute>), typeof(object))]
public class PropertyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is IEnumerable<IPropertyEditorAttribute>)
{
IEnumerable<IPropertyEditorAttribute> list = value as IEnumerable<IPropertyEditorAttribute>;
foreach (IPropertyEditorAttribute cur in list)
{
if (cur.Name.Equals(parameter.ToString(), StringComparison.InvariantCultureIgnoreCase))
{
return cur.Value;
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
好吧,我oppertunity是,當用戶改變PropertyGrid中的佈局,觸發應反應,改變模板。
有誰知道,我該怎麼做?
迎接帕特里克
他已經使用選擇器... –