我有一些 wpf 窗口、一些類和一個視圖模型。不知何故,當(dāng)我告訴它時,輸入字段的值不會綁定,并且視圖模型中的值保持為 NULL。我實(shí)際上繼續(xù)使用該值,但在調(diào)試過程中意識到它有一個 NULL 值。在輸入窗口中:<dx:ThemedWindow x:Class="DXEbayManager.NewProductsMenu" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" Title="NewProductsMenu" Height="200" Width="450"> <StackPanel> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="3*" /> </Grid.ColumnDefinitions> <Label Content="Product Name: " Grid.Column="0"/> <TextBox x:Name="ProductNameBox" Text="{Binding ProductName}" Grid.Column="1"/> </Grid> </StackPanel></dx:ThemedWindow>在我的 ViewModel 中我有:public class NewProductsMenuVM : ViewModelBase { public string ProductName { get; set; } public static NewProductsMenuVM Instance { get; } = new NewProductsMenuVM(); }我想在這里使用該值(其中為 NULL): public partial class NewProductsMenu : ThemedWindow { public void saveToDB() { string ProductName = NewProductsMenuVM.Instance.ProductName; } }我沒有最好的調(diào)試技巧,但后面的值{get; set; }也已經(jīng)是NULL了。為什么會發(fā)生這種情況?有什么方法可以解決它?
C# - 獲??;放; 保持 NULL
慕工程0101907
2023-09-24 15:47:47