i am trying to override the wpf toolkit propertygrid's style. Therefore i modified the generic.xaml.
Now i have the problem that the defaulteditors styles are not overridden.
Therefore i wrote following style to override the PropertyGridEditorComboBox in Xaml:
<Style TargetType="{x:Type xctk:PropertyGridEditorComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox SelectedItem="{Binding Value}" ItemsSource="{?????}" />
</ControlTemplate>
</Setter.Value>
</Setter>
This snippet seems to work except the fact that i do not know what i have to bind as an itemssource. What do i have to bind as Itemssource?
If there is also a better way to override the DefaultEditors appearance please let me know.
KR Manuel
You have to reach from the style to the control it's applied to -- something like this:
ItemsSource="{TemplateBinding ItemsSource}"
(Assuming that PropertyGridEditorComboBox has an ItemsSource property.)
Related
I am developing a custom control derived from an ItemsControl. In the generic.xaml-file I created the style for that control and also defined an ItemTemplate:
<Style TargetType="local:MyItemsControl">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="Red">
<!-- Other things in here -->
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
I want to bind the Background property of the Border in the DataTemplate to a dependency property of the MyItemsControl.
If found several questions here suggesting to use the element name of the MyItemsControl in the binding, but that only works when defining the ItemTemplate where the control is being used. I also tried binding to a RelativeSource defining the local:MyItemsControl as ancestor type.
Nothing worked. What am I missing here?
What`s the type of that DependencyProperty? Is it Brush or string?
This simple code works for me:
Background="{Binding Name, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Just for test here I bind to Name property of ItemsControl that is 'Yellow' - and it works.
I am currently working with avalon dock v2, in the template of my document sources, i'm also putting in a docking manager.
Yes for each of my document, I want anchorable panes inside it. But when I try to do that, it doesn't work, it just shows the toString of the docking manager for each of the document, is there a way to fix that.
Also, how do i default dock my anchorable?
Thanks and Regards,
Kev84
In creating a template for the AvalonDock's LayoutDocument (via the LayoutDocumentControl) I also came across a similar issue. The solution was to set the ContentSource of the ContentPresenter to point to the Model property of my control. The code below illustrates it:
<!--The LayoutDocument is templated via the LayoutDocumentControl-->
<Style TargetType="{x:Type ad:LayoutDocumentControl}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ad:LayoutDocumentControl}">
<ScrollViewer
Background="AliceBlue"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True">
<!--Make sure that the ContentSource points the Model Property of the Control-->
<ContentPresenter
Content="{Binding Path=Content, UpdateSourceTrigger=PropertyChanged}"
ContentSource="{Binding Path=Model, UpdateSourceTrigger=PropertyChanged}"
/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
A similar approach should apply to your case. This is just a temptative answer (since I am also new to AvalonDock 2.0), but it may be worth trying.
Live long and prosper!
I want to use templated ComboBoxItems which consist of an Image and a Label. If I assign the template to a ComboBoxItem, can I somehow set the Source-Property of the Image? The goal is to use the same template for different ComboBoxItems but with different pictures in each Item.
I also thought about binding the Image.Source-Property in the Template, but this fails because the "parent" ComboBoxItem has of course no Source-Property I could bind to.
The code illustrates my problem:
<Style x:Key="ComboBoxPictureItem" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<StackPanel Orientation="Horizontal">
<Image x:Name="StatusImage" />
<Label x:Name="StatusLabel" Content="Green"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ComboBox>
<ComboBoxItem Style="{StaticResource ResourceKey=ComboBoxPictureItem}"
-> sth. like: StatusImage.Source="PathToMyImage.png"/>
</ComboBox>
Thank you!
You should use template bindings to expose internal properties, e.g. bind the Label's content to the ComboBoxItem's content:
<Label Content="{TemplateBinding Content}"/>
If you now set the Content outside it is transferred to the label, you can do the same for the image, you may run out of properties though so if you want to do things that way you could inherit from ComboBoxItem and create more properties.
Here i do not think you want to mess with control templates really, just use the ItemTemplate to specify how the items look.
I Have this very simple xaml style problem in Silverlight4.
When I set a style on element through explicit styling my implicit style is removed?
I created a simple example to illustrate the problem.
<UserControl.Resources>
<Style TargetType="TextBox">
<Setter Property="Background" Value="red"/>
</Style>
<Style TargetType="FrameworkElement" x:Key="test">
<Setter Property="Margin" Value="20"/>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<TextBox Style="{StaticResource test}" Height="40" Width="120"> </TextBox>
</Grid>
</UserControl>
So when I remove the Style="{StaticResource test}
the implicit style is applied again.
Note: this is oversimplified example. So moving the margin to the texbox style is not an option because the real project contains larger xaml styling.
Does somebody know a solution or can confirm that this isn't possible?
Thx in advance!
Take a look at the BasedOn style property. This will allow you to inherit from a base style, to use the base properties and add some changes.
Now, there is a problem with BasedOn - it can't be used with an implicit style. However, this is pretty easy to work around. This article demonstrates the work around and will also explain the BasedOn property a bit better:
Silverlight how-to: Inherit from an Implicit Style
How do i define a TemplateBinding for my custom control?
a little somthing like this..... (btw, this xaml is WPF, not silverlight--which is slightly different)
<style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Green">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background={TemplateBinding Background}
</ControlTemplate>
</Setter.Value>
</Setter>
</style>
now, once you apply this style to an object, whenever you set the background of that object, the template will use the Background property (this is a property on the button control) and will be defaulted to what you set in the style (in this case, green)
If you want to use a property that does not exsist on the object of your style, you have to derive your own control and add the property as either a DependencyProperty or use the INotifyPropertyChanged interface. Here is a decent explanation for you.
Need a bit more information on what you are trying to do. Setting up a TemplateBinding can be done with the following XAML:
{TemplateBinding YourProperty}
or
{Binding RelativeSource={RelativeSource TemplatedParent}, Path=YourProperty}