Я хочу создать простой вид свойств, в котором можно изменить каждое значение.Определить автоматически сгенерированный TextBox
Свойства сгруппированы по одному имени, как это:
- name1: property1, свойство2
- name2: property1, свойство2
- ...
S о я создал DataGrid с шаблоном для заполнения сетки (обратите внимание, что я удалил все свойства стиля и т.д., а текстовые значения также являются только примерами):
<DataGrid Name="propertyGrid">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Property Group Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding propertyGroupName}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Property 1">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding property1}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Property 2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding property2}" TextChanged="TextBox_TextChanged" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Как вы можете видеть, что я сейчас пытаюсь добавить a TextChanged
, и есть моя проблема: откуда я могу получить информацию propertyGroupName
, так как мне нужно только изменить property2
от определенного propertyGroup
.
Я готов для любой подсказку или решение ... может быть, «auto gen datagrid» - не лучшее решение здесь?
Редактировать Мой код позади. Здесь вы можете увидеть страницу, заполняющий DataGrid
и класс я связывающийся с (обратите внимание, что метод GetPropertyX
просто читает мой файл свойств):
public PropertiesPage()
{
InitializeComponent();
List<PropertyGroup> properties = new List<PropertyGroup>();
properties.Add(GetPropertyGroup("propertyGroup1"));
properties.Add(GetPropertyGroup("propertyGroup2"));
properties.Add(GetPropertyGroup("propertyGroup3"));
propertyGrid.ItemsSource = properties;
}
private PropertyGroup GetPropertyGroup(string propertyGroupName)
{
return new CarrierConfig()
{
PropertyGroupName = propertyGroupName,
Property1 = GetProperty1(propertyGroupName),
Property2 = GetProperty2(propertyGroupName)
};
}
public class PropertyGroup
{
public string PropertyGroupName { get; set; }
public string Property1 { get; set; }
public string Property2 { get; set; }
}
вы ищете сетку недвижимости? если да, посмотрите [здесь] (http://wpg.codeplex.com/) – Muds
Нет надежного способа сделать это с помощью DataGrid. Если вы публикуете класс, на который вы привязаны, я могу вам помочь. Возможно, TreeView с HierarchicalDataTemplate будет хорошим выбором. – Domysee
@Muds спасибо, я посмотрю на это! – Sonnywhite