Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. What's Wrong With This Style?

What's Wrong With This Style?

Scheduled Pinned Locked Moved WPF
htmlcssdesignhelpquestion
3 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I'm creating a theme with a base style for all controls:

    <FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
    <sys:Double x:Key="Font.Size.Header1">18</sys:Double>
    <sys:Double x:Key="Font.Size.Header2">16</sys:Double>
    <sys:Double x:Key="Font.Size.Header3">14</sys:Double>
    <sys:Double x:Key="Font.Size.Normal">12</sys:Double>

    <SolidColorBrush x:Key="TextBlock.Static.Background" Color="Transparent"/>
    <SolidColorBrush x:Key="TextBlock.Static.Foreground" Color="DarkGray"/>

    <Style x:Key="ControlBase" TargetType="{x:Type Control}">

    <Setter Property="Control.FontSize" Value="{StaticResource Font.Size.Normal}"/>
    <Setter Property="Control.FontFamily" Value="{StaticResource Font.Family.Default}"/>
    <Setter Property="Control.HorizontalAlignment" Value="Center"/>
    <Setter Property="Control.VerticalAlignment" Value="Center"/>
    

    </Style>

    <Style TargetType="{x:Type TextBlock}"
    BasedOn="{StaticResource ControlBase}">

    <Setter Property="Background" Value="{StaticResource TextBlock.Static.Background}"/>
    <Setter Property="Foreground" Value="{StaticResource TextBlock.Static.Foreground}"/>
    

    </Style>

    I'm trying to use it like this:

    <TextBlock Grid.Row="0"
    Grid.Column="0"
    Text="Test"
    Margin="22,0,0,0"/>

    The designer wont load, and when I run it I get

    System.Windows.Markup.XamlParseException
    Message='Initialization of 'System.Windows.Controls.TextBlock' threw an exception.' Line number '56' and line position '20'.

    Inner Exception 1:
    InvalidOperationException: Can only base on a Style with target type that is base type 'TextBlock'.
    

    What's wrong here??

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    L 1 Reply Last reply
    0
    • K Kevin Marois

      I'm creating a theme with a base style for all controls:

      <FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
      <sys:Double x:Key="Font.Size.Header1">18</sys:Double>
      <sys:Double x:Key="Font.Size.Header2">16</sys:Double>
      <sys:Double x:Key="Font.Size.Header3">14</sys:Double>
      <sys:Double x:Key="Font.Size.Normal">12</sys:Double>

      <SolidColorBrush x:Key="TextBlock.Static.Background" Color="Transparent"/>
      <SolidColorBrush x:Key="TextBlock.Static.Foreground" Color="DarkGray"/>

      <Style x:Key="ControlBase" TargetType="{x:Type Control}">

      <Setter Property="Control.FontSize" Value="{StaticResource Font.Size.Normal}"/>
      <Setter Property="Control.FontFamily" Value="{StaticResource Font.Family.Default}"/>
      <Setter Property="Control.HorizontalAlignment" Value="Center"/>
      <Setter Property="Control.VerticalAlignment" Value="Center"/>
      

      </Style>

      <Style TargetType="{x:Type TextBlock}"
      BasedOn="{StaticResource ControlBase}">

      <Setter Property="Background" Value="{StaticResource TextBlock.Static.Background}"/>
      <Setter Property="Foreground" Value="{StaticResource TextBlock.Static.Foreground}"/>
      

      </Style>

      I'm trying to use it like this:

      <TextBlock Grid.Row="0"
      Grid.Column="0"
      Text="Test"
      Margin="22,0,0,0"/>

      The designer wont load, and when I run it I get

      System.Windows.Markup.XamlParseException
      Message='Initialization of 'System.Windows.Controls.TextBlock' threw an exception.' Line number '56' and line position '20'.

      Inner Exception 1:
      InvalidOperationException: Can only base on a Style with target type that is base type 'TextBlock'.
      

      What's wrong here??

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      TextBlock doesn't inherit from class Control.

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      K 1 Reply Last reply
      0
      • L Lost User

        TextBlock doesn't inherit from class Control.

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        LOL - I knew that. Wow, I need to take a break. Thanks

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups