谁能告诉我为什么我需要点击两次第一次输入新的DataGrid以便我的标签更新它的内容?我试图尽可能多地删除不需要的代码。为什么我需要点击两次DataGrid来更新我的绑定
这是我的XAML
<Window x:Class="PSS.LateOrderPredictor.Ui.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:PSS.LateOrderPredictor.Ui.ViewModel"
Title="MainWindow" Height="600" Width="1350
" WindowState="Maximized">
<Window.Resources>
...
</Window.Resources>
<Window.DataContext>
<vm:SoSummaryViewModel/>
</Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="800"/>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Path=SummaryLineItems}"
SelectedItem="{Binding Path=SelectedSalesOrderViewModel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
...
>
<ListBox.ItemTemplate>
<DataTemplate>
<Expander HorizontalAlignment="Stretch"
MaxHeight="500">
<Expander.Header>
...
</Expander.Header>
<DataGrid ItemsSource="{Binding Path=LineItems}"
SelectedItem="{Binding Path=SelectedDemandEvent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
...
/>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Grid.Column="2"
Grid.Row="0"
<!--Here is the label I am trying to set-->
DataContext="{Binding Path=SelectedSalesOrderViewModel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Content="{Binding SelectedDemandEvent.PartNumber}"/>
...
</Grid>
</Grid>
当我点击DataGridRow
并包含在我的SoSummaryViewModel
类SelectedSalesOrderViewModel
设置。只要点击新的DataGrid
,它就会在第一次点击时开始设置。
public class SoSummaryViewModel : ViewModelBase
{
...
/// <summary>
/// The view model for the grid that contains the SelectedSalesOrderLine
/// </summary>
public SoSummaryLineViewModel SelectedSalesOrderViewModel
{
get { return _selectedSalesOrderViewModel; }
set
{
if (_selectedSalesOrderViewModel != value)
{
_selectedSalesOrderViewModel = value;
OnPropertyChanged("SelectedSalesOrderViewModel");
}
}
}
}
我最初的两次点击(只是需要两次点击,而不是实际的双击事件),标签将更新所选行改变任何时候,只要我保持不变DataGrid
内后。我在里面使用扩展器DataGrid
,扩展器在ListBox
之内。这是一张图片,这可能会让它更加清晰。
我无法在给定的'xaml'中看到'DataGrid'。 – Sinatr 2014-10-30 15:51:23
@Sinatr对不起,现在试试看 - 谢谢 – 2014-10-30 16:02:25