How To Implement Attached Property?
Posted: 04 Aug 2016, 07:02
Another question, let's say I've made a control and want to customize sub-components of that control using xaml. Would I use attached properties to do this? Below I'm trying to assign a border's corner radius in this way. Where have I gone wrong and what needs to change for this to work?
Assigning the dependency property to readonly doesn't seem to be allowed (compile time error).
I could do this differently if everything wasn't required to be a usercontrol.
Maybe change thisto something like this Just a thought though. Admittedly, I don't know how difficult it is to pair xaml with a code behind in noesis.
Assigning the dependency property to readonly doesn't seem to be allowed (compile time error).
I could do this differently if everything wasn't required to be a usercontrol.
Maybe change this
Code: Select all
[Noesis.UserControlSource("Assets/Darren/Code/QuickSwap.xaml")]Code: Select all
[Noesis.Source(Noesis.Border,"Assets/Darren/Code/QuickSwap.xaml")]Code: Select all
<darren:QuickSwap x:Name="m_quickSwap_leftHand" Canvas.Top="75" Canvas.Left="0" Height="150" Width="100" CornerRadius="25" />Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:noesis="clr-namespace:NoesisGUIExtensions"
x:Class="Darren.QuickSwap" Opacity=".5">
<Border x:Name="m_border" Background="#FF595959" BorderBrush="Black" BorderThickness="5" />
</UserControl>
Code: Select all
namespace Darren
{
[Noesis.UserControlSource("Assets/Darren/Code/QuickSwap.xaml")]
public class QuickSwap : Noesis.UserControl
{
#region Variables & Properties
private Noesis.Border m_border = null;
#region Attached Properties
/// <summary>
/// EX) http://www.codemag.com/article/1405061
/// </summary>
public Noesis.CornerRadius CornerRadius
{
get
{
// Retrieve Value
return (Noesis.CornerRadius)GetValue(CornerRadiusProperty);
}
set
{
// Mirror value to subcomponent
if (null == m_border)
{
m_border = FindName("m_border") as Noesis.Border;
}
if (null != m_border)
{
m_border.CornerRadius = value;
}
// Assign Value
SetValue(CornerRadiusProperty, value);
}
}
/// <summary>
///
/// </summary>
public static Noesis.DependencyProperty
CornerRadiusProperty =
Noesis.DependencyProperty.Register(
"CornerRadius",
typeof(Noesis.CornerRadius), typeof(QuickSwap),
new Noesis.PropertyMetadata(""));
#endregion Attached Properties
#endregion Variables & Properties
/// <summary>
/// Initialization.
/// </summary>
public void OnPostInit()
{
}
}
}