Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to style a button through code
    primarykey
    data
    text
    <p>I'm trying to give a style I made in blend to a button that generates in the code. I tried the following but it doesn't seem to work. I also can't find any solutions online.</p> <p>Here is the code.</p> <pre><code>private void createBtn() { Button btn = new Button(); btn.Name = buttonName; btn.Style = popUpStyle; btn.Margin = new Thickness(20); btn.Content = "Close"; btn.Click += new RoutedEventHandler(btn_Click); btn.Visibility = System.Windows.Visibility.Visible; Canvas.Children.Add(btn); } </code></pre> <p>And the xaml.</p> <pre><code>&lt;Style x:Name="popUpStyle" TargetType="Button"&gt; &lt;Setter Property="Background" Value="Transparent"/&gt; &lt;Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/&gt; &lt;Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/&gt; &lt;Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/&gt; &lt;Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/&gt; &lt;Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/&gt; &lt;Setter Property="Padding" Value="10,3,10,5"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate x:Name="popUpStyleCT" TargetType="Button"&gt; &lt;Grid Background="Transparent" Height="150" Width="200"&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup x:Name="CommonStates"&gt; &lt;VisualState x:Name="Normal"/&gt; &lt;VisualState x:Name="MouseOver"/&gt; &lt;VisualState x:Name="Pressed"/&gt; &lt;VisualState x:Name="Disabled"/&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;Rectangle Fill="#FFC2C2C2" Margin="0,15,0,0"/&gt; &lt;Rectangle Fill="#FF313197" Height="15" Stroke="Black" VerticalAlignment="Top" Opacity="0.25"/&gt; &lt;Rectangle Fill="#FFE20303" HorizontalAlignment="Right" Height="15" Stroke="Black" VerticalAlignment="Top" Width="30" Opacity="0.25"/&gt; &lt;TextBlock HorizontalAlignment="Right" Height="15" TextWrapping="Wrap" Text="X" VerticalAlignment="Top" Width="14" FontSize="13.333" Margin="0,0,5,0"/&gt; &lt;Rectangle Fill="#FF4D4A4A" Height="22" Margin="50,0,44,8" VerticalAlignment="Bottom" Stroke="Black"/&gt; &lt;Border x:Name="ButtonBackground" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" Margin="0,12,0,34"&gt; &lt;ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Margin="-3,2,73,0" Foreground="Black" FontSize="13.333" VerticalAlignment="Top" HorizontalAlignment="Left"/&gt; &lt;/Border&gt; &lt;TextBlock Height="15" TextWrapping="Wrap" Text="Close" VerticalAlignment="Bottom" FontSize="13.333" Margin="85,0,81,12" Foreground="Black"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
    singulars
    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