在 GridViewColumn.CellTemplate 中的 StackPanel 中对 TextBlock 进行 MultiBinding,但文本不显示

MultiBinding a TextBlock in a StackPanel in a GridViewColumn.CellTemplate and the Text does not show

我有一个带有 Gridview 的 ListView,对于一些列,我需要有两行数据。最上面的是物品数量,底部是物品数量乘以数量。我可以让最高金额显示得很好,但底部金额没有显示。我在后端部分设置了中断以确保提取正确的数量并返回正确的数字,但是当我 运行 程序时它不会显示。

<Window x:Class="Listviewissue.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    xmlns:local="clr-namespace:Listviewissue">
<Window.Resources>
    <local:AmountQuantityConverter x:Key="AmtQConverter"/>

</Window.Resources>
<Grid >
    <ListView Name="lstBids" Margin="3" Grid.ColumnSpan="4" Grid.Row="1" MinHeight="200">
        <ListView.View>
            <GridView>
                <GridViewColumn Header ="Q">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Margin="1"  Text="{Binding Path=Quantity}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header ="Sub Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Margin="1"  Text="{Binding Path=SubContractorName}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header ="Sub Amt">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Margin="1"  Text="{Binding Path=SubContractorAmount, StringFormat={}{0:C}}"/>
                                <TextBlock Margin="1">
                                    <TextBlock.Text>
                                        <MultiBinding Converter="{StaticResource AmtQConverter}" StringFormat="{}{0:C}}">
                                            <Binding Path="Quantity" />
                                            <Binding Path="SubContractorAmount"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

这里是后面的cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace Listviewissue
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        LoadBox();
    }

    private void LoadBox()
    {
        BidSheet bs = new BidSheet();
        bs.ReadFromDatabase("Test");
       lstBids.ItemsSource = bs.BidSheetLineItems;
    }
}

public class AmountQuantityConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        // Return the total value of all the items in stock.
        decimal quantity = decimal.Parse(values[0].ToString());
        decimal amt = decimal.Parse(values[1].ToString());
        decimal result = (quantity * amt);
        return result;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}



public class BidSheet
{
    public BidSheet()
    {
        BidSheetLineItems = new BidSheetLineItems();
    }
    public BidSheetLineItems BidSheetLineItems { get; set; }

    public void ReadFromDatabase(string file)
    {
        BidSheet bidSheet = new BidSheet();
        System.Xml.Serialization.XmlSerializer reader =
        new System.Xml.Serialization.XmlSerializer(typeof(BidSheet));
        System.IO.StreamReader xmlFile = new System.IO.StreamReader(
            file + ".xml", true);
        bidSheet = (BidSheet)reader.Deserialize(xmlFile);

        BidSheetLineItems = bidSheet.BidSheetLineItems;

        xmlFile.Close();
    }
    }


public class BidSheetLineItems : List<BidSheetLineItem>
{


}

public class BidSheetLineItem
{
    public BidSheetLineItem()
    {
        Quantity = 0;
        SubContractorName = "";
        SubContractorAmount = 0;
    }
    public double Quantity { get; set; }
    public string SubContractorName { get; set; }
    public decimal SubContractorAmount { get; set; }
}

}

这是一个包含一些数据的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<BidSheet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<BidSheetLineItems>
    <BidSheetLineItem>
      <Quantity>1</Quantity>
      <SubContractorName>Harry</SubContractorName>
  <SubContractorAmount>50</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>5</Quantity>
  <SubContractorName>Arther</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>2</Quantity>
  <SubContractorName>Bill</SubContractorName>
  <SubContractorAmount>340000</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>3</Quantity>
  <SubContractorName>Fred</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>5</Quantity>
  <SubContractorName>Ron</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>1</Quantity>
  <SubContractorName>Goerge</SubContractorName>
  <SubContractorAmount>60</SubContractorAmount>
</BidSheetLineItem>
  </BidSheetLineItems>
</BidSheet>

提前致谢,如果您需要更多信息来帮助我,请告诉我。

好的,我明白了。我有

<MultiBinding Converter="{StaticResource AmtQConverter}" StringFormat="{}{0:C}}">

而且需要

<MultiBinding Converter="{StaticResource AmtQConverter}"  StringFormat="{}{0:C}">