0

我已经创建了带有文本框的窗口,我正在使用 MVVM 模式,为了填充它,我有包含对象的视图模型类,现在我需要将它与 Text 属性绑定

public log Event
{
  get { return mEvent; }
  set { mEvent = value; }
}

弹出一个窗口来显示数据现在我想在窗口中填充数据

<TextBlock x:Name="xCategyTextBox" Grid.Column="1"  Grid.Row="0" TextAlignment="Center" Margin="5" Text="{Binding Path=Event.Category}"/> 

<TextBlock x:Name="xLevTextBox" Grid.Column="1"  Grid.Row="1" TextAlignment="Center" Margin="5" Text="{Binding Path=Event.Type}"/>

在 Xaml.cs 中

WindowsEventsAutoMountViewModel windows = new WindowsEventsAutoMountViewModel(logEntry);
this.DataContext = windows.Event;
4

1 回答 1

0

你设置

this.DataContext = windows.Event; 

并具有此绑定:

{Binding Path=Event.Category}

似乎一个Event太多了;从两行之一中删除它。

于 2012-05-30T15:25:04.570 回答