誰能告訴我爲什麼我需要點擊兩次第一次輸入新的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