This project has moved and is read-only. For the latest updates, please go here.

Bind CollectionControl isEnabled property and style

Sep 25, 2014 at 5:32 PM
I have managed to bind the IsEnabled property of a variable displayed in a CollectionEditor by editing Xceed.Wpf.Toolkit\CollectionControl\Themes\Generic.xaml using EditorTemplateDefinition as follows:
<pg:PropertyGrid.EditorDefinitions>
  <pg:EditorTemplateDefinition TargetProperties="UConstruction">
    <pg:EditorTemplateDefinition.EditingTemplate>
      <DataTemplate>                                              
        <TextBox Text="{Binding Value}" IsEnabled="{Binding Instance.IsUYConstruction}" />
       </DataTemplate>
     </pg:EditorTemplateDefinition.EditingTemplate>
   </pg:EditorTemplateDefinition>
 </pg:PropertyGrid.EditorDefinitions>
                                    
This, however, overwrites the default style for that row of the CollectionControl with a Textbox.

Is there a way to achieve the IsEnabled binding but keep the default CollectionControl style?
Developer
Sep 26, 2014 at 1:42 PM
Hi,

You can try with a PropertyGridEditorTextBox :
<xctk:PropertyGrid.EditorDefinitions>
            <xctk:EditorTemplateDefinition TargetProperties="UConstruction">
               <xctk:EditorTemplateDefinition.EditingTemplate>
                  <DataTemplate>
                     <xctk:PropertyGridEditorTextBox Text="{Binding Value}"
                                                     IsEnabled="{Binding Instance.IsUYConstruction}" />
                  </DataTemplate>
               </xctk:EditorTemplateDefinition.EditingTemplate>
            </xctk:EditorTemplateDefinition>
</xctk:PropertyGrid.EditorDefinitions>
Sep 29, 2014 at 10:32 AM
Thanks for the help.

It turns out, I actually needed PropertyGridEditorDoubleUpDown, i.e. I edited Xceed.Wpf.Toolkit\CollectionControl\Themes\Generic.xaml as follows:
<pg:PropertyGrid.EditorDefinitions>
  <pg:EditorTemplateDefinition TargetProperties="UConstruction">
    <pg:EditorTemplateDefinition.EditingTemplate>
      <DataTemplate>
        <editor:PropertyGridEditorDoubleUpDown Value="{Binding Value}"
                        IsReadOnly="{Binding Instance.IsLayerConstruction}"
                        TextAlignment="Left"                                                                                    
                        />
      </DataTemplate>
    </pg:EditorTemplateDefinition.EditingTemplate>
  </pg:EditorTemplateDefinition>
</pg:PropertyGrid.EditorDefinitions>
where
xmlns:pg="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid"
xmlns:editor="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid.Editors"
What is the easiest/best way to change the text (foreground) colours depending on whether the IsReadOnly property is True or False?

Items without an EditorDefinition defined have different colours for properties that are ReadOnly and those that aren't.
(I am using the ExpressionDark style)

Thanks again.
Developer
Sep 29, 2014 at 2:39 PM
Hi,

You can set a style on the PropertyGridEditorDoubleUpDown and use a trigger to change the color when IsReadOnly is true.
 <Window.Resources>      
      <Style x:Key="DoubleUpDownStyle"
             TargetType="{x:Type xctk:PropertyGridEditorDoubleUpDown}">
         <Setter Property="TextAlignment"
                 Value="Left" />
         <Setter Property="Foreground"
                 Value="Green" />
         <Style.Triggers>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}"
                         Value="True">
               <Setter Property="Foreground"
                       Value="Red" />
            </DataTrigger>
         </Style.Triggers>
      </Style>
</Window.Resources>

....

<xctk:PropertyGrid x:Name="_propertyGrid">
         <xctk:PropertyGrid.EditorDefinitions>
            <xctk:EditorTemplateDefinition TargetProperties="UConstruction">
               <xctk:EditorTemplateDefinition.EditingTemplate>
                  <DataTemplate>
                     <xctk:PropertyGridEditorDoubleUpDown Value="{Binding Value}"
                                                          IsReadOnly="{Binding Instance.IsUYConstruction}"
                                                          Style="{StaticResource DoubleUpDownStyle}"/>
                  </DataTemplate>
               </xctk:EditorTemplateDefinition.EditingTemplate>
            </xctk:EditorTemplateDefinition>
         </xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>