我想綁定TextBox
對象的屬性,我不能讓它的工作。文本框綁定
我想這兩種用途既不作品:
<TextBox Name="textBoxZbozi" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="1"
VerticalContentAlignment="Center" Text="{Binding Path=Artikl_CODE, ElementName=vybranyRadek}" />
<TextBlock Name="textBlockArtikl" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="1"
Text="{Binding Path=vybranyRadek.Artikl_NAME}" TextWrapping="Wrap" />
視圖模型:
private Radek vybranyRadek;
public Radek VybranyRadek
{
get
{
return this.vybranyRadek;
}
set
{
this.vybranyRadek = value;
NotifyPropertyChanged("VybranyRadek");
}
}
和Radek
類:
public class Radek
{
public bool ZASKRTNUTO { get; set; }
public string ID { get; set; }
public string Artikl_ID { get; set; }
public string Artikl_NAME { get; set; }
public string Artikl_CODE { get; set; }
public string Sarze_ID { get; set; }
public string Sarze_NAME { get; set; }
public string Sarze_POPIS { get; set; }
public string Umisteni_ID { get; set; }
public string Umisteni_NAME { get; set; }
public double Mnozstvi { get; set; }
public string Jednotka { get; set; }
}
vybranyRadek
應創建並填充了一些數據。這是我如何分配數據:
Radek temp = ((Radek)dataGrid.SelectedItem);
viewModel.VybranyRadek = temp;
我在哪裏做錯了?
你在哪裏分配datacontext,你是否指定它? –
對不起,我沒有包含它,但'this.DataContext = viewModel;'在'窗口'構造函數 – Sk1X1
'vybranyRadek'應該是第一個字母大寫'VybranyRadek' – Pikoh