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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WCF and WF
  4. UIElement as a StaticResource

UIElement as a StaticResource

Scheduled Pinned Locked Moved WCF and WF
csstutorialquestion
3 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    spiritboy
    wrote on last edited by
    #1

    hi there, i was wondering on how to use my defined Button in Grid.Resources to fill my 2X2 Grid???!!!!

    <Grid><
    < Grid.Resources>
    <Button x:Key = "btn">TEST</Button>
    </Grid.Resources>
    <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefenitions>
    <RowDefinition/>
    <RowDefinition/>
    </Grid.RowDefenitions>
    ????????????????
    ????????????????
    ????????????????
    </Grid>

    if there is no way, so {StaticResource ...} is only worked over properties! i mean : Property = {StaticResource ...}?????

    E 2 Replies Last reply
    0
    • S spiritboy

      hi there, i was wondering on how to use my defined Button in Grid.Resources to fill my 2X2 Grid???!!!!

      <Grid><
      < Grid.Resources>
      <Button x:Key = "btn">TEST</Button>
      </Grid.Resources>
      <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefenitions>
      <RowDefinition/>
      <RowDefinition/>
      </Grid.RowDefenitions>
      ????????????????
      ????????????????
      ????????????????
      </Grid>

      if there is no way, so {StaticResource ...} is only worked over properties! i mean : Property = {StaticResource ...}?????

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      <StaticResourceExtension ResourceKey="btn" />

      I apologize for posting this code without testing. I posted another answer here[^].

      Eslam Afifi

      modified on Monday, August 10, 2009 12:21 PM

      1 Reply Last reply
      0
      • S spiritboy

        hi there, i was wondering on how to use my defined Button in Grid.Resources to fill my 2X2 Grid???!!!!

        <Grid><
        < Grid.Resources>
        <Button x:Key = "btn">TEST</Button>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefenitions>
        <RowDefinition/>
        <RowDefinition/>
        </Grid.RowDefenitions>
        ????????????????
        ????????????????
        ????????????????
        </Grid>

        if there is no way, so {StaticResource ...} is only worked over properties! i mean : Property = {StaticResource ...}?????

        E Offline
        E Offline
        Eslam Afifi
        wrote on last edited by
        #3

        Sorry about the previous post. You can't reuse the same instance of a button (resources are dictionaries) twice. Besides that resource extensions don't let you specify dependency properties so you won't be able to set the Grid.Row property for example. So I think you should use either styles or maybe custom controls. Here is a tested code.

        <Grid>
        <Grid.Resources>
        <Style x:Key="HelloWorldButton" TargetType="{x:Type Button}">
        <EventSetter Event="Click" Handler="Button_Click" />
        <Setter Property="Content" Value="Hello, world!" />
        </Style>
        </Grid.Resources>

        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <Button Style="{StaticResource HelloWorldButton}" />
        <Button Grid.Column="1" />
        <Button Grid.Row="1" />
        <Button Grid.Row="1" Grid.Column="1" Style="{StaticResource HelloWorldButton}" />
        

        </Grid>

        private void Button_Click(object sender, RoutedEventArgs e)
        {
        var sndr = sender as Button;
        if (sndr != null)
        {
        var gridRow = (int)sndr.GetValue(Grid.RowProperty);
        var gridColumn = (int)sndr.GetValue(Grid.ColumnProperty);
        MessageBox.Show("Hello, world!" + Environment.NewLine
        + "Button at row " + gridRow + ", column " + gridColumn + " was clicked.");
        }
        }

        Eslam Afifi

        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