This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello there, I have two questions: 1. I am trying to style the ReadOnlyDisplayKey, but the properties which I set don't seem to have any effect. I can change the font size for some reason however - can you tell me what I am doing wrong? Here is the code snippet I am using: < Mindscape:BuiltInEditorStyle EditorKey="{x:Static Mindscape:PropertyGrid.ReadOnlyDisplayKey}"><Style TargetType="{x:Type TextBlock}"> <Setter Property="Background" Value="Transparent" /> <Setter Property="Padding" Value="10" /> </Style> </Mindscape:BuiltInEditorStyle> 2. Can you give me a clue on what syntax to use in order to place these BuiltInEditorStyles into a ResourceDictionary? I have tried a few different ways, but it doesn't seem to work at all - all of my other grid styles are in a ResourceDictionary and are working well. Thanks, Justin. |
|
|
Hi Justin, 1. You are doing nothing wrong. The current implementation of the built-in editors imposes certain limitations on styling -- if a property is set explicitly in the built-in editor then it cannot be overridden using styling alone. This is not normally a problem because if you want to make such changes then you can style the Control.Template property (it is on the wishlist to address though). However, ReadOnlyDisplayKey uses a TextBlock which is not a Control and therefore doesn't have a template. In this case, the workaround is to hijack the key and replace the entire DataTemplate. There's an example of this (in another context) at http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1171. Here's how this might apply in your case: <DataTemplate x:Key="{x:Static ms:PropertyGrid.ReadOnlyDisplayKey}"> (Those converter resources are as described in the other thread.) Regarding the specific case of transparency, note that the editor sits within a TreeListView in the default template. This has its own background so you may need to retemplate in order to get transparency. 2. This is working okay for me using normal resource dictionary merging syntax: <Window.Resources> And then the built-in editor styles go in Styles.xaml. (You should also be able to do the merge at the application level.) Let me know if this still doesn't work for you. |
|
|
Thanks Ivan! ReadOnlyDisplayKey is styled exactly how I want it now. More on 2.) The DataTemplate you described is now in my PropertyGrid ResourceDictionary along with my other general styles. However, when a cut and paste one of my BuiltInEditorStyles into my ResourceDictionary I get a problem, sepcifically "All objects added to an IDictionary must have a key attribute or some other type of Key attribute associated with them" - I've added a key but get more markup problems. I know this is a simple syntax problem - so how should I be implementing this? This is what I have added to the resource dictionary: < Mindscape:BuiltInEditorStyle EditorKey="{x:Static Mindscape:PropertyGrid.SimpleTextEditorKey}"><Style TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Mindscape:TextBox}"> <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </Mindscape:BuiltInEditorStyle> |
|
|
Ah, I misunderstood what you were trying to do. What I was doing was this: In the ResourceDictionary: <Style x:Key="myStyle" ... In the grid declaration: <ms:BuiltInEditorStyle EditorKey="{x:Static ms:PropertyGrid.XxxKey}" Style="{StaticResource myStyle}" /> Would that meet your requirement? If you need to capture the actual mapping of keys to styles in your ResourceDictionary, I will have to have a bit more of a think! |
|
|
Thanks Ivan, that's just what I needed... simple when you know how. |
|