Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:59:02+00:00 2026-06-03T10:59:02+00:00

I’m writing my first custom user control against WinRT, and I’ve run into a

  • 0

I’m writing my first custom user control against WinRT, and I’ve run into a problem.

I would like to expose an image, PART_NwBadge and it’s visibility as Dependency Properties in my control. Then I would like to supply default values through setters in the style. This part is not working. Instead, the default value from the DependencyProperty (in BadgedButton.cs) is being applied.

Is it even possible to do what I’ve described? Or should I be setting the default values in the C# code? If I do need to set the values in the C# code, would someone comment on how to load image resources in code? After a great deal of searching I’ve yet to find a solution that works.

Finally, since this is my first serious attempt at writing a custom control, please suggest any improvements I could make, even if they are not directly related to the problem.

Windows 8 Consumer Preview
C#/WinRT/Metro
Visual Studio 11 Beta

Themes/Generic.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="using:InkSdkTestApplication.Controls">

    <Style TargetType="l:BadgedButton">
        <Setter Property="Width" Value="36"/>
        <Setter Property="Height" Value="36"/>
        <Setter Property="Background" Value="#1C1C1C"/>
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="NwBadge">
            <Setter.Value>
                <Image Width="16" Height="16" Source="../Assets/mouse_16x16.png"/>            
            </Setter.Value>
        </Setter>
        <Setter Property="NwBadgeVisibility" Value="Collapsed"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="l:BadgedButton">
                    <Border x:Name="PART_Border"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">

                        <Grid>
                            <ContentPresenter x:Name="PART_Content"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                              Content="{TemplateBinding Content}"/>

                            <Image x:Name="PART_NwBadge"
                                   HorizontalAlignment="Left"
                                   VerticalAlignment="Top"
                                   Width="16" Height="16"
                                   Visibility="{TemplateBinding NwBadgeVisibility}"
                                   Source="{TemplateBinding NwBadge}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Controls/BadgedButton.cs

namespace InkSdkTestApplication.Controls
{
    public sealed class BadgedButton : Control
    {
        #region // Dependency Properties
        public static DependencyProperty ContentProperty =
            DependencyProperty.Register(
                "Content",
                typeof(FrameworkElement),
                typeof(BadgedButton),
                new PropertyMetadata(null));

        public static DependencyProperty NwBadgeProperty =
            DependencyProperty.Register(
                "NwBadge",
                typeof(Image),
                typeof(BadgedButton),
                new PropertyMetadata(null));

        public static DependencyProperty NwBadgeVisibilityProperty =
            DependencyProperty.Register(
                "NwBadgeVisibility",
                typeof(Visibility),
                typeof(BadgedButton),
                new PropertyMetadata(Visibility.Visible));
        #endregion

        #region // Public Properties
        public FrameworkElement Content
        {
            get { return (FrameworkElement)GetValue(ContentProperty); }
            set { SetValue(ContentProperty, value); }
        }

        public Image NwBadge
        {
            get { return (Image)GetValue(NwBadgeProperty); }
            set { SetValue(NwBadgeProperty, value); }
        }

        public Visibility NwBadgeVisibility
        {
            get { return (Visibility)GetValue(NwBadgeVisibilityProperty); }
            set { SetValue(NwBadgeVisibilityProperty, value); }
        }
        #endregion

        public BadgedButton()
        {
            this.DefaultStyleKey = typeof(BadgedButton);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:59:06+00:00Added an answer on June 3, 2026 at 10:59 am

    http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.