Posted 13 years ago
by Pat Maneely
-
Software Engineering Manager,
Cobham Aerospace
I'm trying to disable an expanding selectively based on a property in my View Model.
The Data Context of the XAML is bound to the VM. The VM has property called Count that indicates the number of parts in the system. I need to Collapse and Hide (or Disable) one or more of the Categories in the PropertyGrid.
How Do I do this? I was trying to use a MultiDataTrigger, but I can't figure out how to link to the Datacontext.
Here's the XAML...
<Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Category" />
<Condition Binding="{Binding DisplayName, RelativeSource={RelativeSource Self}}" Value="Misc" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Hidden" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Category" />
<Condition Binding="{Binding DisplayName, RelativeSource={RelativeSource Self}}" Value="System #1" />
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type RpWin:SystemData}}, Path=Count}" Value="0" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Hidden" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
<wizard:Wizard x:Name="configSetupWizard" WindowTitleBehavior="PageTitle" WindowTitleBaseText="Configuration Wizard"
PageSequenceType="Stack" BackwardProgressTransitionDuration="0:0:0.5" ForwardProgressTransitionDuration="0:0:0.5"
HelpButtonVisible="False" IsWindowDialogResultUpdatingEnabled="True">
<wizard:Wizard.TransitionSelector>
<shared:MultiTransitionSelector>
<shared:BarWipeTransition />
</shared:MultiTransitionSelector>
</wizard:Wizard.TransitionSelector>
<wizard:WizardPage x:Name="msmFSPPage"
Caption="System Configuration Parameters"
Description="This page contains the Parameters necessary to configuration System"
Title="System Configuration Parameters Page"
HelpButtonVisible="False"
NextButtonEnabled="{Binding Path=SysData.CapableSystem}"
FinishButtonEnabled="{Binding Path=FlexCommSysData.P25CapableSystem, Converter={StaticResource BoolInverterConverter}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
MinHeight="{Binding RelativeSource={RelativeSource Self}, Path=Content.MinHeight}"
Content="Configuration Name" />
<TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
MaxLines="1" Margin="-100,0,0,0" HorizontalAlignment="Stretch" Width="Auto"
Text="{Binding Path=SysData.Name}"/>
<propgrid:PropertyGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
IsSummaryVisible="True"
SelectedObject="{Binding Path=SysData}">
<propgrid:PropertyGrid.DataFactory>
<propgrid:TypeDescriptorFactory />
</propgrid:PropertyGrid.DataFactory>
</propgrid:PropertyGrid>
</Grid>
</wizard:WizardPage>
The VM has a Property called SysData. In SysData is a Property called Count. When 'Count' = 0 I need to disable/Hide the 'System #1' Category Expander so that the user can't select any children properties.
The Data Context of the XAML is bound to the VM. The VM has property called Count that indicates the number of parts in the system. I need to Collapse and Hide (or Disable) one or more of the Categories in the PropertyGrid.
How Do I do this? I was trying to use a MultiDataTrigger, but I can't figure out how to link to the Datacontext.
Here's the XAML...
<Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Category" />
<Condition Binding="{Binding DisplayName, RelativeSource={RelativeSource Self}}" Value="Misc" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Hidden" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding DataAccessorType, RelativeSource={RelativeSource Self}}" Value="Category" />
<Condition Binding="{Binding DisplayName, RelativeSource={RelativeSource Self}}" Value="System #1" />
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type RpWin:SystemData}}, Path=Count}" Value="0" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Hidden" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
<wizard:Wizard x:Name="configSetupWizard" WindowTitleBehavior="PageTitle" WindowTitleBaseText="Configuration Wizard"
PageSequenceType="Stack" BackwardProgressTransitionDuration="0:0:0.5" ForwardProgressTransitionDuration="0:0:0.5"
HelpButtonVisible="False" IsWindowDialogResultUpdatingEnabled="True">
<wizard:Wizard.TransitionSelector>
<shared:MultiTransitionSelector>
<shared:BarWipeTransition />
</shared:MultiTransitionSelector>
</wizard:Wizard.TransitionSelector>
<wizard:WizardPage x:Name="msmFSPPage"
Caption="System Configuration Parameters"
Description="This page contains the Parameters necessary to configuration System"
Title="System Configuration Parameters Page"
HelpButtonVisible="False"
NextButtonEnabled="{Binding Path=SysData.CapableSystem}"
FinishButtonEnabled="{Binding Path=FlexCommSysData.P25CapableSystem, Converter={StaticResource BoolInverterConverter}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
MinHeight="{Binding RelativeSource={RelativeSource Self}, Path=Content.MinHeight}"
Content="Configuration Name" />
<TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
MaxLines="1" Margin="-100,0,0,0" HorizontalAlignment="Stretch" Width="Auto"
Text="{Binding Path=SysData.Name}"/>
<propgrid:PropertyGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
IsSummaryVisible="True"
SelectedObject="{Binding Path=SysData}">
<propgrid:PropertyGrid.DataFactory>
<propgrid:TypeDescriptorFactory />
</propgrid:PropertyGrid.DataFactory>
</propgrid:PropertyGrid>
</Grid>
</wizard:WizardPage>
The VM has a Property called SysData. In SysData is a Property called Count. When 'Count' = 0 I need to disable/Hide the 'System #1' Category Expander so that the user can't select any children properties.