Question

I'm using Mahapp Metro buttons in a wpf project. Some of the standard buttons have a converter defined in the contentpresenter of the original mahapp template.

f.e. squarebutton:

<ContentPresenter x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content, Converter={StaticResource ToLowerConverter}}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
OpacityMask="{x:Null}" />

Is there a simple way I can change the squarebutton to NOT use the ToLowerConverter without changing the whole template?

I tried changing the ContentTemplate in a style, but without success:

<Style x:Key="MyFlyoverButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource SquareButtonStyle}">     
    <Setter Property="ContentTemplate">
        <Setter.Value>  
            <DataTemplate>
                <TextBlock Text="{TemplateBinding Content}"   VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" />
            </DataTemplate>         
        </Setter.Value>
    </Setter> 
</Style>
Was it helpful?

Solution

Changing the ContentTemplate won't help you because that is just used by the that you want to replace. You could use something like the following to access a ContentPresenter, but this only works on a per UI element basis from a UI collection, eg. you could use this to access the single ContentPresenter defined in a template from a ListBoxItem that has that template applied:

ContentPresenter contentPresenter = FindVisualChild(dependencyObject);

As that is no use to you, I won't bother showing the code for that method. The only other alternative you have is to define a new ControlTemplate. It should be a simple matter to define a new ControlTemplate if you have access to the default ControlTemplate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top