有没有人有任何关于如何解决我的问题的建议?我有一个数据网格绑定到ModelCheckoutRecord
个对象(ListModelCheckoutRecords
)的集合。我将所选项目绑定到ModelCheckoutRecord
(SelectedItemModelCheckoutRecord
)。在所选项的绑定中,我想更新另一个datagrid和gridsplitter(ResponseVisibility
)的可见性绑定。从其他绑定更新绑定的能力似乎不起作用?
我的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");
}
}
由于
理查德
答案 0 :(得分:2)
假设您确实希望在仅null
SelectedItem
的情况下获得折叠可见性,那么实际上不需要使用代码。以下XAML将完成这项工作。
只需为源DataGrid提供一个名称(我在以下示例中假设Grid为名称)并在目标DataGrid中使用样式,如下所示:
<DataGrid x:Name="TargetGridJustToShowWhereThisGoes">
<DataGrid.Style>
<Style TargetType="DataGrid">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Grid, Path=SelectedItem}" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Style>
</DataGrid>