Click here to Skip to main content
15,513,571 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sorry if the name of the question is too long, I don't really know how to make it smaller because English isn't my native language.

NOTE: It is UWP C#, not C# alone (XAML + C#). Also, the icon is from the font "Segoe MDL2 Assets". My goal is to make the button with the icon and normal text. The reason why I don't use an image because the icon that I have is better than any other icons that we can download (and it is better quality).

So, I want to make an textblock that already have text inside have a button as parent. I searched on Google but they aren't about my subject. Only one question matched with my problem BUT the answer is by doing
XML
<Button ...><StackPanel><TextBlock .../></StackPanel></Button>
but it is what I already have done.

What I have tried:

I tried to make like I showed above: "
XML
<Button ...><StackPanel><TextBlock .../></StackPanel></Button>
". My code is
XML
<Button FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent">
    <StackPanel>
        <TextBlock Text="Settings" FontSize="18" VerticalAlignment="Center"/>
    </StackPanel>
</Button>
Posted
Updated 26-Jul-22 7:11am

1 solution

You're trying to set both the Content property and the content of the element. You can't set both at the same time.

Try:
XAML
<Button Background="Transparent">
    <StackPanel>
        <TextBlock FontFamily="Segoe MDL2 Assets" Text="" Width="50" Height="50"/>
        <TextBlock Text="Settings" FontSize="18" VerticalAlignment="Center"/>
    </StackPanel>
</Button>
 
Share this answer
 
Comments
Le lance Flamer 2022 27-Jul-22 9:48am    
Thanks

I realized before any solution on the question. I even added another stackpanel inside the stack panel because it was glitchy for some reasons.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900