将List <t>传递给wpf中的MultiBinding转换器

时间:2017-07-01 20:10:25

标签: wpf multibinding

我的ViewModel上有一个List作为属性。我希望通过XAML中的MultiBinding将此List作为参数传递给TextBlock。如何做到这一点?

 <DataGrid VerticalScrollBarVisibility="Visible" x:Name="Dg_Prices" CanUserReorderColumns="True" ItemsSource="{Binding CurrentRec.Current_Item_Price_Details}"  CanUserResizeColumns="False" CanUserResizeRows="False" AutoGenerateColumns="False" CanUserAddRows="false" VirtualizingPanel.IsVirtualizing="False" >
                        <DataGrid.Columns>
                                <DataGridTemplateColumn Header="Percentage(%)" Width="1,*" x:Name="Percentage">
                                <DataGridTemplateColumn.CellTemplate >
                                    <DataTemplate>
                                        <DataGridCell >
                                            <ContentControl >
                                                <TextBlock Width="auto" Height="auto"  FontSize="14" FontWeight="Bold" Foreground="Navy">
                                                    <TextBlock.Resources>
                                                        <local:TaxId2PercentageConverter x:Key="TaxPerConv" />
                                                    </TextBlock.Resources>

                                                    <TextBlock.Text>
                                                        <MultiBinding Converter="{StaticResource TaxPerConv}" Mode="OneWay">
                                                            <Binding Path="DCIM.Lst_Tax" />
                                                            <Binding Path="TaxId"/>
                                                        </MultiBinding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </ContentControl>
                                        </DataGridCell>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>

                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>

ViewModel相关部分的快照如下: -

public class MyViewModel : INotifyPropertyChanged
{
 HexaEntities DbContext = new HexaEntities();
 private List<hexa_tax> p_Lst_Tax = new List<hexa_tax>();
 public List<hexa_tax> Lst_Tax
     {
        get { return p_Lst_Tax; }
        set
        {
            if(p_Lst_Tax!=value)
            {
                p_Lst_Tax = value;
                RaisePropertyChangedEvent("Lst_Tax");

            }
        }
    } 


 public MyViewModel ()
        {
          Lst_Tax = DbContext.hexa_tax.ToList<hexa_tax>();
        }


    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChangedEvent(string Property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Property));
        }
    }
 }

Lst_tax是List<T>,即我的ViewModel上的一个属性,我想传递给这个TextBlock,但它是转换器,它给了我一个例外说:  无法转换类型&#39; MS.Internal.NamedObject&#39;输入&#39; System.Collections.Generic.List`1

0 个答案:

没有答案