如何将图像和更多文本添加到组描述中?

时间:2022-03-03 01:08:22

How do I add an image to the group description, and add some more text next to it?

如何将图像添加到组描述中,并在其旁边添加更多文本?

Here is what I have right now :

这就是我现在所拥有的:

如何将图像和更多文本添加到组描述中?

I want the logos to be beside the description, and want some different text at the blue marks like "5x108" for the Ferrari and "5x114.3" for Dodge. But that is stored next to it in the table

我希望徽标与描述不同,并希望在蓝色标记处有一些不同的文字,如法拉利的“5x108”和道奇的“5x114.3”。但是它存储在表格旁边

I have all my data stored inside ms sql, and here is how I retrieve it :

我将所有数据存储在ms sql中,以下是我检索它的方法:

string connStrings = ConfigurationManager.AppSettings["Sql"];
    string Data = @"Select ps.Mærket AS Mærke, P.DataID, P.Billed, P.Model, P.Årgang, P.[Motor Type], P.Krydsmål, P.Centerhul, P.ET,P.Bolter, P.Dæk, P.Fælge from Data.Hjuldata P  inner join Data.Mærke PS on P.MærkeID = PS.MærkeID ORDER BY ps.Mærket";
public MainWindow()
{
    InitializeComponent();

    BindData();

    ICollectionView dataView = CollectionViewSource.GetDefaultView(hjuldata.ItemsSource);
    dataView.GroupDescriptions.Add(new PropertyGroupDescription("Mærke"));
}

private void BindData()
{
    hjuldata.Items.Clear();
    hjuldata.ItemsSource = kategori().Tables[0].DefaultView;
}

public DataSet kategori()
{
    //SQL statement to fetch entries from data
    DataSet dsdata = new DataSet();

    //Open SQL Connection
    using (SqlConnection conns = new SqlConnection(connStrings))
    {
        conns.Open();

        //Initialize command object
        using (SqlCommand cmds = new SqlCommand(Data, conns))
        {
            SqlDataAdapter adapters = new SqlDataAdapter(cmds);

            //Fill the result set
            adapters.Fill(dsdata);
        }
    }

    return dsdata;
}

What I am trying in XAML

我在XAML中尝试的是什么

<ListView.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Expander IsExpanded="False"  BorderBrush="#FFEAEAEA" BorderThickness="0,0,0,1">
                                <Expander.Header>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" VerticalAlignment="Bottom"/>
                                        <Image Source="{Binding Path=logo}" Width="20" Height="20" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
                                        <TextBlock Text="{Binding text}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
                                    </StackPanel>
                                </Expander.Header>
                                <ItemsPresenter />
                            </Expander>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListView.GroupStyle>

What do I need to do to make my Group Header include some of the detail data? Change my XAML, change my object model, etc.

我需要做些什么才能使我的Group Header包含一些详细数据?更改我的XAML,更改我的对象模型等。

1 个解决方案

#1


0  

and this solved it

这解决了它

<StackPanel Orientation="Horizontal" DataContext="{Binding Items}">
<Image Source="{Binding Path= Billed}" Width="20" Height="20" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
<TextBlock Text="{Binding Path=Mærke}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding Path=Krydsmål}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
</StackPanel>

如何将图像和更多文本添加到组描述中?

#1


0  

and this solved it

这解决了它

<StackPanel Orientation="Horizontal" DataContext="{Binding Items}">
<Image Source="{Binding Path= Billed}" Width="20" Height="20" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
<TextBlock Text="{Binding Path=Mærke}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" VerticalAlignment="Bottom"/>
<TextBlock Text="{Binding Path=Krydsmål}" FontWeight="Bold" Foreground="#FFEAEAEA" FontSize="22" VerticalAlignment="Bottom"/>
</StackPanel>

如何将图像和更多文本添加到组描述中?