0

我使用 WPF 并通过 ItemsSource 填充 ListView 并在某些控件中绑定源的每个元素但是当我尝试绑定文本框时它不会更新源这里是我的代码...

<ListView Name="LB_PedidosRepartidor" Margin="0,37,6,10" Grid.Row="1" Grid.Column="1">
        <ListView.View>
            <GridView AllowsColumnReorder="False" Selector.IsSelected="False">
                <GridViewColumn Width="50">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="../IMG/Order.png" Width="25"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="N° Orden" Width="65" DisplayMemberBinding="{Binding Path=Orden}"/>
                <GridViewColumn Header="Fecha" Width="150" DisplayMemberBinding="{Binding Path=Fecha}"/>
                <GridViewColumn Header="Código" Width="65" DisplayMemberBinding="{Binding Path=Codigo}"/>
                <GridViewColumn Header="Nombre" Width="150" DisplayMemberBinding="{Binding Path=Nombre}"/>
                <GridViewColumn Header="Dirección" Width="160" DisplayMemberBinding="{Binding Path=Dirección}"/>
                <GridViewColumn Header="Estado" Width="130">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox SelectedValue="{Binding Path=id_status}" DisplayMemberPath="Nombre_Estado" SelectedValuePath="id_estado" Loaded="ComboBox_Loaded">
                                <ComboBox.Style>
                                    <Style TargetType="ComboBox">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=id_status}" Value="3">
                                                <Setter Property="Background" Value="White"/>
                                                <Setter Property="Foreground" Value="Gray"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=id_status}" Value="4">
                                                <Setter Property="Background" Value="Green"/>
                                                <Setter Property="Foreground" Value="LightGray"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=id_status}" Value="5">
                                                <Setter Property="Background" Value="Red"/>
                                                <Setter Property="Foreground" Value="LightGray"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=id_status}" Value="6">
                                                <Setter Property="Background" Value="Red"/>
                                                <Setter Property="Foreground" Value="LightGray"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=id_status}" Value="8">
                                                <Setter Property="Background" Value="Blue"/>
                                                <Setter Property="Foreground" Value="White"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ComboBox.Style>
                            </ComboBox>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Informacion" Width="200">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=Info}" Width="180"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn> 
                <GridViewColumn Header="Factura" Width="150" DisplayMemberBinding="{Binding Path=Factura}"/>
                <GridViewColumn Header="Paqueteria" Width="150" DisplayMemberBinding="{Binding Path=Paqueteria}"/>
            </GridView>
        </ListView.View>
    </ListView>

这是用数据表填充列表视图的代码

private void GetOrdersFrom()
    {
        if (CB_Repartidor.SelectedIndex != -1)
        {
            try
            {
                StringBuilder oSB = new StringBuilder();
                SAPbobsCOM.Recordset oRS = (SAPbobsCOM.Recordset)DAL.GetCompany().GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                DataTable oDT = new DataTable();
                DataRow oDR;
                oDT.Columns.Add("Orden", typeof(int));
                oDT.Columns.Add("Fecha");
                oDT.Columns.Add("Codigo");
                oDT.Columns.Add("Nombre");
                oDT.Columns.Add("Dirección");
                oDT.Columns.Add("id_status", typeof(int));
                oDT.Columns.Add("id_statusAnt", typeof(int));
                oDT.Columns.Add("Info", typeof(string));
                oDT.Columns.Add("ComentariosAnt", typeof(string));
                oDT.Columns.Add("Factura");
                oDT.Columns.Add("Paqueteria");
                oRS.DoQuery("SELECT id_ruta FROM emb_Repartidor WHERE Codigo = " + CB_Repartidor.SelectedValue + " AND id_ruta IS NOT NULL ");
                if (oRS.Fields.Count > 0)
                {
                    if (((DataRowView)CB_Repartidor.SelectedItem)["Status"].ToString() == "Asignado")
                        LB_PedidosRepartidor.IsEnabled = false;
                    else LB_PedidosRepartidor.IsEnabled = true;
                    id_ruta = (int)oRS.Fields.Item("id_ruta").Value;
                    oSB.Append("SELECT T1.DocEntry, Convert(varchar(30),T0.Fecha_Asignado,100) DocDueDate, T4.TrnspName, Convert(varchar(30),T1.DocDueDate,107) Date , ")
                        .Append("convert(varchar(10),dbo.FN_StringTime(T1.DocTime),108) Tiempo, T1.CardCode, T1.CardName, T1.Address, T2.Status, T3.Comentarios, ")
                        .Append(" MAX(Case T5.TargetType When 15 Then T8.DocNum When 13 Then T7.DocNum End) Factura ")
                        .Append("FROM emb_rutas_pedidos T0 INNER JOIN ORDR T1 ON T0.id_pedido = T1.DocEntry ")
                        .Append("INNER JOIN emb_pedidos T2 ON T0.id_pedido = T2.DocEntry ")
                        .Append("Inner Join (Select M0.id_ruta_pedido, MAX(M0.Status) As Status, MAX(M0.Comentarios) As Comentarios, MAX(M0.id) As ID ")
                        .Append("From dbo.emb_pedidos_status_historial M0 Group By M0.id_ruta_pedido) T3 On T0.id = T3.id_ruta_pedido ")
                        .Append("INNER JOIN OSHP T4 ON T1.TrnspCode = T4.TrnspCode ")
                        .Append("Inner Join RDR1 T5 ON T5.DocEntry = T1.DocEntry ")
                        .Append("Left Join DLN1 T6 On T5.TrgetEntry = T6.DocEntry And T5.TargetType = 15 ")
                        .Append("Left Join OINV T7 On T5.TrgetEntry = T7.DocEntry And T5.TargetType = 13 ")
                        .Append("Left Join OINV T8 On T6.TrgetEntry = T8.DocEntry And T6.TargetType = 13 ")
                        .Append("WHERE T0.id_ruta = ").Append(id_ruta)
                        .Append(" GROUP BY T1.DocEntry, T1.DocDueDate, T0.Fecha_Asignado,  T1.CardCode, T1.CardName, T1.Address, T2.Status, T3.Comentarios, T4.TrnspName, T0.Orden, T1.DocTime ")
                        .Append(" Order By T0.Orden");
                    oRS.DoQuery(oSB.ToString());
                    oRS.MoveFirst();
                    while (!oRS.EoF)
                    {
                        oDR = oDT.NewRow();
                        oDR["Orden"] = oRS.Fields.Item("DocEntry").Value;
                        oDR["Fecha"] = oRS.Fields.Item("DocDueDate").Value + "\n"+ oRS.Fields.Item("Date").Value + " " + oRS.Fields.Item("Tiempo").Value;
                        oDR["Codigo"] = oRS.Fields.Item("CardCode").Value;
                        oDR["Nombre"] = oRS.Fields.Item("CardName").Value;
                        oDR["Dirección"] = oRS.Fields.Item("Address").Value;
                        oDR["id_status"] = oRS.Fields.Item("Status").Value;
                        oDR["id_statusAnt"] = oRS.Fields.Item("Status").Value;
                        oDR["Info"] = oRS.Fields.Item("Comentarios").Value.ToString();
                        oDR["ComentariosAnt"] = oRS.Fields.Item("Comentarios").Value.ToString();
                        oDR["Factura"] = oRS.Fields.Item("Factura").Value;
                        oDR["Paqueteria"] = oRS.Fields.Item("TrnspName").Value;
                        oDT.Rows.Add(oDR);
                        oRS.MoveNext();
                    }
                    LB_PedidosRepartidor.ItemsSource = oDT.DefaultView;
                }
                else
                {
                    GetRepartidores();
                    LB_PedidosRepartidor.Items.Clear();
                }
            }
            catch (Exception) { }
        }
    }

我已经尝试使用绑定属性 Mode 和 UpdateSourceTrigger 请帮助我我需要它

4

0 回答 0