locked
Use timer to change background image in a Hub control?

    Question

  • I'm working on an app using a Hub Control. My goal is to make the first HubSection a image slider that is using a DispatcherTimer to change the background image each 10-15 seconds.  I have so far named the HubSection "ActionSection" and added my first picture as a ImageBrush in the Hubsection.Background. I have also created the timer to change the pictures, but some how I can't figure out how to get the HubSection control named "ActionSection". I'm I doing it all wrong?

    Thanks, Sigurd F

    Thursday, February 20, 2014 10:57 PM

Answers

  • Hi Sigurd F,

    How to get HubSection named ActionSection? If you assign the x:Name for the control then you can use the name at the cs file backend. I don't see any reason that cannot get HubSection by name.

    A possible situation is when you type something in .cs without saving the .xaml, the red wavy underline will display since the IDE cannot recognize which element you are talking about. Save the .xaml and then use the name in .cs file is ok.

    Or do I miss understand something?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Sigurd F Friday, February 21, 2014 2:01 PM
    Friday, February 21, 2014 1:20 AM
    Moderator

All replies

  • Hi Sigurd F,

    How to get HubSection named ActionSection? If you assign the x:Name for the control then you can use the name at the cs file backend. I don't see any reason that cannot get HubSection by name.

    A possible situation is when you type something in .cs without saving the .xaml, the red wavy underline will display since the IDE cannot recognize which element you are talking about. Save the .xaml and then use the name in .cs file is ok.

    Or do I miss understand something?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Sigurd F Friday, February 21, 2014 2:01 PM
    Friday, February 21, 2014 1:20 AM
    Moderator
  • Thanks, the x: made the difference. What is the difference between "Name" and "x:Name"?

    Regards, Sigurd F

    Friday, February 21, 2014 2:01 PM
  • Hi Sigurd,

    Take a look at the documentation of x:Name attribute.


    Some types used in Windows Runtime XAML also have a property named Name. For example, FrameworkElement.Name and TextElement.Name.

    If Name is available as a settable property on an element, Name and x:Name can be used interchangeably in XAML, but an error results if both attributes are specified on the same element. There are also cases where there's a  Name property but it's read-only (like VisualState.Name). If that's the case you always use x:Name to name that element in the XAML and the read-only Name exists for some less-common code scenario.

    Typically, XAML for a user interface is created by using a design tool such as Microsoft Expression Blend. XAML as created by design tool output typically generates x:Name attributes consistently on elements, even in cases where there would be an equivalent Name property available.

    Note  FrameworkElement.Name generally should not be used as a way to change values originally set by x:Name, although there are some scenarios that are exceptions to that general rule. In typical scenarios, the creation and definition of XAML namescopes is a XAML processor operation. Modifying FraemworkElement.Name at run time can result in an inconsistent XAML namescope / private field naming alignment, which will be hard to keep track of in your code-behind.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, February 24, 2014 1:28 AM
    Moderator
  • Thanks.

    Sigurd F

    Monday, February 24, 2014 7:27 AM