第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# - 獲??;放; 保持 NULL

C# - 獲??;放; 保持 NULL

C#
慕工程0101907 2023-09-24 15:47:47
我有一些 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ā)生這種情況?有什么方法可以解決它?
查看完整描述

1 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個贊

您需要將DataContext窗口的實(shí)例設(shè)置為NewProductsMenuVM某處的實(shí)例,例如在構(gòu)造函數(shù)中:


public partial class NewProductsMenu : ThemedWindow

{

    public NewProductsMenu()

    {

        InitializeComponent();

        DataContext = NewProductsMenuVM.Instance;

    }


    ...

    public void saveToDB()

    {

        string ProductName = NewProductsMenuVM.Instance.ProductName;

    }

}


查看完整回答
反對 回復(fù) 2023-09-24
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號