Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a WPF UserControl programmatically has no style
    primarykey
    data
    text
    <p>I'm trying to create a button-like UserControl which consists of a border and a label. When adding this UserControl directly in the XAML of MainWindow, it renders correctly (it is put in a WrapPanel), but if I add it programmatically it doesn't look the same at all. There is no border, no background color, the text size of the label is wrong and so is the text color.</p> <p>This is my user control:</p> <pre><code>&lt;UserControl x:Class="Jishi.SonosPartyMode.UserControls.Player" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="150" d:DesignWidth="300" Width="200" Height="100"&gt; &lt;Border BorderBrush="#086EAA" CornerRadius="8,8,8,8" BorderThickness="4" Margin="15" Padding="15px" VerticalAlignment="Center" Background="#0A4069"&gt; &lt;Label Name="PlayerName" TextElement.Foreground="White" TextElement.FontSize="20px"&gt;asdasdasd&lt;/Label&gt; &lt;/Border&gt; &lt;/UserControl&gt; </code></pre> <p>when adding it, I just invoke it like this:</p> <pre><code>var button = new Player { Content = player.Properties.RoomName, DataContext = player.Properties.UDN }; PlayerList.Children.Add( button ); </code></pre> <p>PlayerList is the actual WrapPanel and Player is my UserControl. I have tried finding information regarding this, but I don't find anything. If you have another approach that I can take, please come with suggestions. All I want is a clickable area with some rounded corners that can contain text (one or more rows).</p> <p>I can apply styles programatically, but the styles defined in the xaml for the UserControl isn't preserved (Border, Margins, colors etc).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload