简体   繁体   English

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

[英]How to bind more than one DataSet column value to a GroupStyle TextBlock

I have the following DataSet with the "PART" DataTable Column bound as the PropertyGroupDescription.我有以下数据集,其中“部分”数据表列绑定为 PropertyGroupDescription。 I also want to bind the "DESCRIPTION" Column, but without biding it to the PropertyGroupDescription, because that would effect the grouping.我还想绑定“DESCRIPTION”列,但不将其绑定到 PropertyGroupDescription,因为这会影响分组。

What I get right now:我现在得到的:

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

What I want to get:我想得到什么:

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

As all of the rows with the same Part number share the same Description.因为具有相同部件号的所有行共享相同的描述。

Current Code:当前代码:

CS: 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: 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,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" /> should work assuming that all rows with the same Part share the same Description and that there is a column named "DESCRIPTION" in the DataTable . <Binding Path="Items[0].DESCRIPTION" />应该假设具有相同部分的所有行共享相同的描述,并且DataTable中有一个名为“DESCRIPTION”的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM