我希望这里有人可以帮助我。我很沮丧。
所以这是我的问题:
我有一个属性列表,这些属性是控件的属性。现在我必须在我的属性网格和控件本身之间建立一个绑定。我的控件模板如下所示:
<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>
属性转换器
[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();
}
好吧,我的机会是,当用户更改属性网格中的布局时,触发器应该做出反应并更改模板。
有谁知道,我怎么能做到这一点?
迎接帕特里克