如何将多个DataSet列值绑定到GroupStyle TextBlock

问题描述

我有以下数据集,其“ PART”数据表列绑定为PropertyGroupDescription。我还想绑定“ DESCRIPTION”列,但不要将其绑定到PropertyGroupDescription,因为这会影响分组。

我现在得到的是:

ID | NAME
PART: 1
1  | AAA
2  | BBB
PART: 2
3  | CCC
PART: 3
4  | DDD
5  | EEE

我想要得到什么:

ID | NAME
PART: 1,DESCRIPTION: ATLANTA
1  | AAA
2  | BBB
PART: 2,DESCRIPTION: NEW YORK
3  | CCC
PART: 3,DESCRIPTION: BOSTON
4  | DDD
5  | EEE

由于具有相同部件号的所有行共享相同的描述。

当前代码

CS:

public DataTable DataGridParts;
readonly CollectionViewSource mycollection;

public void FillDataGridParts()
{
    sqlCommand cmd = new sqlCommand
    {
        CommandType = CommandType.Text,CommandText = "SELECT * FROM [PARTS] WHERE [STA_SID] = @StaSid AND [OWNER] LIKE @Search COLLATE latin1_general_CI_AI ORDER BY LEN ([PART]),[PART] ASC,[DESCRIPTION] DESC,[SHARE] DESC",Connection = sqlConnection.con
    };
    cmd.Parameters.AddWithValue("@StaSid",GlobalStrings.building_sta_sid);
    cmd.Parameters.AddWithValue("@Search",'%' + textBox_search_part.Text + '%');

    Mouse.OverrideCursor = Cursors.Wait;
    sqlDataAdapter da = new sqlDataAdapter(cmd);
    DataGridParts.Clear();
    da.Fill(DataGridParts);
    datagrid_parts.ItemsSource = DataGridParts.defaultview;
    mycollection.GroupDescriptions.Clear();
    mycollection.GroupDescriptions.Add(new PropertyGroupDescription("PART"));
    datagrid_parts.ItemsSource = mycollection.View;
    Mouse.OverrideCursor = null;;
}

XAML:

<DataGrid.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style targettype="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate targettype="{x:Type GroupItem}">
                            <StackPanel>
                                <TextBlock Height="20" Padding="0,3,0" FontWeight="SemiBold" Background="#e4e4e4">
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}PART: {0},DESCRIPTION: {1}">
                                            <Binding Path="Name" />
                                            <Binding Path="???" /> //NO IDEA HOW TO BIND HERE
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                                <ItemsPresenter/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</DataGrid.GroupStyle>

解决方法

<Binding Path="Items[0].DESCRIPTION" />应该在假定具有相同部件的所有行共享相同的描述并且DataTable中有一个名为“ DESCRIPTION”的列的情况下工作。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...