Configure / Bind WinRT User Control Properties

I am trying to develop my own control for a WinRT / Metro application.

This has a dependency property, and I would like to be able to set its value within a custom control. However, using SetValue interrupts any bindings that users of the control can create.

None of the solutions I found (e.g. SetCurrentValue) seem to apply to WinRT / Metro. Is there a solution to this?

It sounds like a simple thing, and - honestly! “I tried to find a solution here and elsewhere.” Any help would be greatly appreciated.

+5
source share
1 answer

PropertyMetadata (Dr. WPF snippets !).

#region IsAvailable
private static bool DefaultIsAvailable = false;

/// <summary>
/// IsAvailable Dependency Property
/// </summary>
public static readonly DependencyProperty IsAvailableProperty =
    DependencyProperty.Register(
        "IsAvailable",
        typeof(bool),
        typeof(CustomControl1),
        new PropertyMetadata(DefaultIsAvailable, OnIsAvailableChanged));

/// <summary>
/// Gets or sets the IsAvailable property. This dependency property 
/// indicates ....
/// </summary>
public bool IsAvailable
{
    get { return (bool)GetValue(IsAvailableProperty); }
    set { SetValue(IsAvailableProperty, value); }
}

/// <summary>
/// Handles changes to the IsAvailable property.
/// </summary>
/// <param name="d">
/// The <see cref="DependencyObject"/> on which
/// the property has changed value.
/// </param>
/// <param name="e">
/// Event data that is issued by any event that
/// tracks changes to the effective value of this property.
/// </param>
private static void OnIsAvailableChanged(
    DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var target = (CustomControl1)d;
    bool oldIsAvailable = (bool)e.OldValue;
    bool newIsAvailable = target.IsAvailable;
    target.OnIsAvailableChanged(oldIsAvailable, newIsAvailable);
}

/// <summary>
/// Provides derived classes an opportunity to handle changes
/// to the IsAvailable property.
/// </summary>
/// <param name="oldIsAvailable">The old IsAvailable value</param>
/// <param name="newIsAvailable">The new IsAvailable value</param>
protected virtual void OnIsAvailableChanged(
    bool oldIsAvailable, bool newIsAvailable)
{
}
#endregion

*

- , , OneWay - ie - - .

Mode="TwoWay" - , ( ) , .

+2

All Articles