Привязка имени свойства не загружается, но другие берутся из сетки

Я использую правильное имя привязки для своего свойства, поскольку оно соответствует имени в таблице из базы данных, другие имена отображают и загружают данные. В чем еще может быть проблема с моей привязкой к этому имени RM_Code?

// код xaml для привязки имени свойства

`<Label Content = "Micros" FontWeight = "SemiBold" HorizontalAlignment = "Left" HorizontalContentAlignment = "Center" VerticalAlignment = "Top" Width = "950" BorderBrush = "#FFBEBEBE" Background = "#FFE3E3E3" BorderThickness = "1.5" Foreground = "Black" Height = "35" VerticalContentAlignment = "Center" FontSize = "14" Margin = "10,350,0,0" Grid.Row = "1"/>
        <DataGrid x:Name = "dgvMicroRecipe" VerticalScrollBarVisibility = "Visible" SelectedCellsChanged = "dgvMacroRecipe_SelectedCellsChanged" CellEditEnding = "dgvMacroRecipe_CellEditEnding" VerticalAlignment = "Top" HorizontalGridLinesBrush = "#FFBBBBBB" AutoGenerateColumns = "False" CanUserDeleteRows = "False" HeadersVisibility = "Column" GridLinesVisibility = "Horizontal" IsReadOnly = "True" FontWeight = "Normal" BorderBrush = "#FF767676" Margin = "10,380,0,0" HorizontalAlignment = "Left" FontSize = "12" Width = "950" Grid.Row = "1">
            <DataGrid.Resources>
                <Style TargetType = "{x:Type DataGridCell}">
                    <Style.Triggers>
                        <Trigger Property = "IsSelected" Value = "True">
                            <Setter Property = "Background" Value = "Blue" />
                            <Setter Property = "BorderBrush" Value = "Blue"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>
            <DataGrid.ColumnHeaderStyle>
                <Style TargetType = "{x:Type DataGridColumnHeader}">
                    <Setter Property = "FontWeight" Value = "SemiBold"/>
                    <Setter Property = "TextElement.FontSize" Value = "14"/>
                    <Setter Property = "Background" Value = "#FF383838"/>
                    <Setter Property = "Foreground" Value = "White"/>
                    <Setter Property = "HorizontalContentAlignment" Value = "Center"/>
                    <Setter Property = "Height" Value = "30"/>
                    <Setter Property = "SeparatorVisibility" Value = "Visible"/>
                </Style>
            </DataGrid.ColumnHeaderStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Binding = "{Binding idx1}" Header = "IDX" Width = "50" IsReadOnly = "True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Left" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding [RM_Code]}" Header = "RM Code" Width = "Auto" IsReadOnly = "True" FontSize = "8">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Left" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn  Visibility = "Visible" Width = "5">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding [Stock Code]}" Header = "Stock Code" Width = "100" IsReadOnly = "True" FontWeight = "SemiBold">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "TextAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center" />
                            <Style.Triggers>
                                <Trigger Property = "Text" Value = "Yes">
                                    <Setter Property = "Background" Value = "LightGreen"/>
                                </Trigger>
                                <Trigger Property = "Text" Value = "No">
                                    <Setter Property = "Background" Value = "#FFFF6969"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding [Stock Description]}" Header = "Stock Description" Width = "150" IsReadOnly = "True" FontWeight = "SemiBold">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "TextAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center" />
                            <Style.Triggers>
                                <Trigger Property = "Text" Value = "Yes">
                                    <Setter Property = "Background" Value = "LightGreen"/>
                                </Trigger>
                                <Trigger Property = "Text" Value = "No">
                                    <Setter Property = "Background" Value = "#FFFF6969"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding [Percentage]}" Header = "Percentage" Width = "100" IsReadOnly = "True" FontWeight = "SemiBold">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "TextAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center" />
                            <Style.Triggers>
                                <Trigger Property = "Text" Value = "Yes">
                                    <Setter Property = "Background" Value = "LightGreen"/>
                                </Trigger>
                                <Trigger Property = "Text" Value = "No">
                                    <Setter Property = "Background" Value = "#FFFF6969"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding Kilograms}" Header = "Kilograms" Width = "100" IsReadOnly = "True" FontWeight = "SemiBold">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Left" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>

                <!-- New Columns Added -->
                <DataGridTextColumn Binding = "{Binding BagWeight}" Header = "Bag-Weight" Width = "100" IsReadOnly = "True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding FullBagUsed}" Header = "Full Bag Used" Width = "100" IsReadOnly = "True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding KgPartBagUsed}" Header = "Kg Part Bag Used" Width = "150" IsReadOnly = "True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Binding = "{Binding TotalKgUsed}" Header = "Total Kg Used" Width = "100" IsReadOnly = "True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType = "{x:Type TextBlock}">
                            <Setter Property = "HorizontalAlignment" Value = "Center" />
                            <Setter Property = "VerticalAlignment" Value = "Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>

`

Я изменил все разные имена для этого свойства привязки, но оно даже не загружало данные из серверной части, как другие столбцы, поскольку их преобразования имен верны. Что еще я мог сделать, чтобы решить эту проблему?

Столько ненужной ерунды, но вы упустили самое главное. Какой ItemsSource у тебя DataGrid? Можете ли вы опубликовать MRE для вашей проблемы - stackoverflow.com/help/minimal-reproducible-example

Peregrine 03.07.2024 08:24
Стоит ли изучать PHP в 2023-2024 годах?
Стоит ли изучать PHP в 2023-2024 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
В JavaScript одним из самых запутанных понятий является поведение ключевого слова "this" в стрелочной и обычной функциях.
Приемы CSS-макетирования - floats и Flexbox
Приемы CSS-макетирования - floats и Flexbox
Здравствуйте, друзья-студенты! Готовы совершенствовать свои навыки веб-дизайна? Сегодня в нашем путешествии мы рассмотрим приемы CSS-верстки - в...
Тестирование функциональных ngrx-эффектов в Angular 16 с помощью Jest
В системе управления состояниями ngrx, совместимой с Angular 16, появились функциональные эффекты. Это здорово и делает код определенно легче для...
Концепция локализации и ее применение в приложениях React ⚡️
Концепция локализации и ее применение в приложениях React ⚡️
Локализация - это процесс адаптации приложения к различным языкам и культурным требованиям. Это позволяет пользователям получить опыт, соответствующий...
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
1
1
50
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Попробуйте использовать это

Binding = "{Binding RM_Code, Mode=TwoWay}"

вместо

Binding = "{Binding [RM_Code]}"

Это должно решить вашу проблему.

Почему вы хотите добавить двустороннюю привязку для чего-то, что отображает только значение?

Peregrine 03.07.2024 14:52

Если вам нужна двусторонняя привязка (данные передаются в обоих направлениях между источником и местом назначения), вы можете добавить свойство. В противном случае игнорируйте его (Binding = "{Binding RM_Code}").

Neelakandan 04.07.2024 07:53

Другие вопросы по теме