有沒有人有任何關於如何解決我的問題的建議?我有一個數據網格綁定到ModelCheckoutRecord
對象集合(ListModelCheckoutRecords
)。我將所選項綁定到ModelCheckoutRecord
(SelectedItemModelCheckoutRecord
)。在所選項目的綁定中,我想更新另一個數據網格和網格分隔器的可見性綁定(ResponseVisibility
)。更新來自其他綁定的綁定的能力似乎不起作用?是使用MVVM中的其他綁定更新WPF中的綁定
這個我的XAML行,如下所示:
<Grid>
<Grid.RowDefinitions>
<View:RowDefinitionExtended Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding ListModelCheckoutRecord}" SelectedItem="{Binding SelectedModelCheckoutRecord}" MouseLeftButtonDown="DataGrid_MouseLeftButtonDown" CommandManager.PreviewExecuted="DataGrid_DeletePreviewExecuted" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="True" Margin="15" Grid.Row="0"/>
<GridSplitter HorizontalAlignment="Stretch" Visibility="{Binding ResponseVisibility}" Grid.Row="1"/>
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding ListModelResponseRecord}" SelectedItem="{Binding SelectedModelResponseRecord}" MouseLeftButtonDown="DataGrid_MouseLeftButtonDown" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" Visibility="{Binding ResponseVisibility}" Margin="15" Grid.Row="2"/>
</Grid>
害我麻煩的精簡代碼如下:
private Visibility responseVisibility = Visibility.Visible;
public Visibility ResponseVisibility
{
get { return responseVisibility; }
set
{
if (value == responseVisibility)
{
return;
}
responseVisibility = value;
RaisePropertyChanged("ResponseVisibility");
}
}
private List<ModelCheckoutRecord> listModelCheckoutRecord;
public List<ModelCheckoutRecord> ListModelCheckoutRecord
{
get { return listModelCheckoutRecord; }
set
{
if (value == listModelCheckoutRecord)
{
return;
}
listModelCheckoutRecord = value;
RaisePropertyChanged("ListModelCheckoutRecord");
ResponseVisibility = Visibility.Collapsed;
}
}
private ModelCheckoutRecord selectedModelCheckoutRecord;
public ModelCheckoutRecord SelectedModelCheckoutRecord
{
get { return selectedModelCheckoutRecord; }
set
{
if (value == null)
{
ResponseVisibility = Visibility.Collapsed;
return;
}
else
{
ResponseVisibility = Visibility.Visible;
}
if (selectedModelCheckoutRecord == value)
{
return;
}
RaisePropertyChanged("SelectedModelCheckoutRecord");
}
}
感謝
理查德
在你的'SelectedModelCheckoutRecord',要設置'ResponseVisibility '根據所選項目是否爲空。在這種情況下,它可能永遠不會爲空,所以可見性總是**可見。重新思考你的邏輯。 –