.net 复杂数据绑定
我希望这里有人能帮助我。我很沮丧 这就是我的问题: 我有一个属性列表,这些属性是控件的属性。现在我必须在我的propertgrid和控件本身之间有一个绑定。我的控件模板如下所示:.net 复杂数据绑定,.net,wpf,xaml,data-binding,binding,.net,Wpf,Xaml,Data Binding,Binding,我希望这里有人能帮助我。我很沮丧 这就是我的问题: 我有一个属性列表,这些属性是控件的属性。现在我必须在我的propertgrid和控件本身之间有一个绑定。我的控件模板如下所示: <DataTemplate x:Key="LabelVisualObject" DataType="{x:Type ContentControl}"> <ContentControl Content="{Binding}" ContentTemplateSelector="{StaticRes
<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();
}
[值转换(typeof(IEnumerable)、typeof(object))]
公共类PropertyConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
if(value!=null&&value为IEnumerable)
{
IEnumerable list=作为IEnumerable的值;
foreach(列表中的iPropertyEdit属性cur)
{
if(cur.Name.Equals(parameter.ToString(),StringComparison.InvariantCultureIgnoreCase))
{
返回当前值;
}
}
}
返回null;
}
公共对象转换回(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
抛出新的NotImplementedException();
}
我的机会是,当用户更改propertygrid中的布局时,触发器应该做出反应并更改模板
有谁知道,我怎么能做到这一点
欢迎Patrik您可能正在寻找一个
DataTemplateSelector
您可以在此处找到有关它的简短教程:
或来自MSDN文档:
ContentTemplateSelector
用于设置ContentTemplate
,您可以尝试通过样式设置ContentTemplate
。同时使用这两个选项将不起作用,ContentTemplateSelector
可能具有as本地值