lepoco / lepoco/wpfui

ContentTemplate doesn't apply to Button

Open
#702 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

I've implement style for Button that wrap the content with ViewBox with overriding ContentTemplate property
But the ContentTemplate doesn't apply to Button's content
` <Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">

            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
            <Setter Property="VerticalContentAlignment" Value="Stretch"></Setter>
            <Setter Property="Padding" Value="5"></Setter>
            <Setter Property="Height" Value="45"></Setter>
            <Setter Property="Width" Value="45"></Setter>
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter>
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Viewbox StretchDirection="Both" Stretch="Uniform" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                            <ContentPresenter  
                                              VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

                            </ContentPresenter>
                        </Viewbox>
                    </DataTemplate>
                </Setter.Value>
            </Setter>

</Style>`

To Reproduce

Override the "DefaultButtonStyle" style and set ContentTemplate

Expected behavior

The ContentTemplate must be applied to content

Screenshots

No response

OS version

Windows 10 x64

.NET version

.Net 7

WPF-UI NuGet version

3.0.0-preview.2

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the XAML example with Button, DefaultButtonStyle, and ContentTemplate in a WPF UI application using WPF-UI 3.0.0-preview.2 on Windows. Trace the Button content presentation behavior and verify that the ViewBox template is applied to the content; the issue names no source file or test, so add focused coverage where the behavior is implemented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.