Hi
I have a XamPropertyGrid-Control with an ReadOnlyTemplate. The Opacity of the ReadOnly-Property seems to be smaller than 1. How can I set it to 1?
<ig:PropertyGridEditorDefinition TargetType="{x:Type sys:Double}" EditTemplate="{StaticResource SpinIntEditor}" ReadOnlyTemplate="{StaticResource IntEditorRO}"/>
<DataTemplate x:Key="IntEditorRO"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Image x:Name="errorImage" Width="16" Height="16" Margin="2" Grid.Column="0" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamPropertyGrid}}}" Visibility="Hidden"> </Image> <TextBox MinWidth="20" Grid.Column="1" Margin="2" Text="{Binding Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> </TextBox> </Grid> </DataTemplate>
Regards, Stephan
Hello Stephan,
XamPropertyGrid uses MaskedInput and DateTimeInput to display fields. Both of these inputs are configured so when the property is readonly/disabled, they will change the opacity of the embedded MaskedInputTextBox.
In order to modify this behavior, you will have to get the default styles of the Inputs(maybe not needed to have both, depends on what fields you intend to style), as well as the grid itself, and modify them accordingly.
You can check the following forum thread where you can find a sample for the same behavior affecting date fields. The approach will be the same, with the only difference your current data template is modified by the MaskedInput -
C:\Program Files (x86)\Infragistics\<version>\WPF\DefaultStyles\MaskedInput\generic.shared.xaml
Please let me know if you have any issues following the steps described in the other post by my colleague.
Sincerely,
Tihomir TonevAssociate Software DeveloperInfragistics
Hi Tihomir
Thanks for your reply. May you have a short example so I can implement much more quickly? I had a related problem with XamDataCards which I could solve quite simple according to https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/83382/how-to-apply-foreground-color-for-disable-isenabled-false-records-in-xamdatagrid. Is there for XamPropertyGrid a similar solution available?
I have been investigating this further, and it would seem that getting the default styles for the read only template will not be needed as the values are represented by the default WPF Textbox and the grayed out behavior comes out of it instead. Please ignore my previous post, since it is wrong.
At first i tried re-styling the texbox and setting the opacity, but that didn't work, so what worked is re-templating it:
<Style x:Key="myTextBoxStyle" TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBoxBase}"> <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"> <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" TargetName="border" Value="1"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="True"> <Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <DataTemplate x:Key="IntEditorRO"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBox MinWidth="20" Grid.Column="1" Margin="2" Text="{Binding Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="Black" Style="{StaticResource myTextBoxStyle}"> </TextBox> </Grid> </DataTemplate>
Maybe not ideal, but I couldn't find any other work around. Please note that in the template the border thickness is set to 0 and I am not sure if this will be the desired value in all cases, so just giving heads up.
I am also attaching the sample I played with for further reference.Should you have any further questions, please let me know.
Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics
XamPropertyGridReadOnlyOpacity.zip