WPT 컨트롤 중 자식 중 하나 (ControlTemplate)에서 읽기 전용 속성을 통해 노출되는 WPF 컨트롤이 있습니다. 지금은 CLR 속성 일 뿐이지 만 그 점이 어떤 차이를 만들지는 모릅니다.XAML을 사용하여 컨트롤의 중첩 된 속성 (속성 값의 속성)을 설정할 수 있습니까?
기본 컨트롤을 인스턴스화하는 XAML에서 자식 컨트롤의 속성 중 하나를 설정할 수 있기를 원합니다. (사실, 나는 그것을 결합하고 싶습니다,하지만 난 그게 좋은 첫 단계가 될 것입니다 설정 생각합니다.) 여기
는 일부 코드입니다 : 여기public class ChartControl : Control
{
public IAxis XAxis { get; private set; }
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.XAxis = GetTemplateChild("PART_XAxis") as IAxis;
}
}
public interface IAxis
{
// This is the property I want to set
double Maximum { get; set; }
}
public class Axis : FrameworkElement, IAxis
{
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(Axis), new FrameworkPropertyMetadata(20.0, FrameworkPropertyMetadataOptions.AffectsRender, OnAxisPropertyChanged));
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
}
내가 중첩 된 설정을 생각할 수있는 두 가지 방법입니다 XAML의 속성 (컴파일하지 않음) :
<!--
This doesn't work:
"The property 'XAxis.Maximum' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'."
"The attachable property 'Maximum' was not found in type 'XAxis'."
-->
<local:ChartControl XAxis.Maximum="{Binding Maximum}"/>
<!--
This doesn't work:
"Cannot set properties on property elements."
-->
<local:ChartControl>
<local:ChartControl.XAxis Maximum="{Binding Maximum}"/>
</local:ChartControl>
이 경우에도 가능합니까?
내가 없으면 템플릿에있는 자식에게 전달되는 기본 컨트롤에 DP를 표시해야합니다. 그렇게 나쁘지는 않겠지 만, 나는 주된 컨트롤에서 속성의 폭발을 피하려고 노력하고 있었다.
건배.
그래, 그게 내가 무슨 생각 :
당신은 그런 일을해야한다. :-( 내 최상위 컨트롤에 여분의 DP가있는 경우! – Swythan
BTW. 예를 들어 XAML 에서처럼 XAxis 속성의 기존 값을 a로 바꾸고 싶지 않습니다. Axis의 새 인스턴스 – Swythan
WPF가 중첩 된 속성에 대한 바인딩을 지원하지 않는 이유는 무엇입니까? 그렇지 않으면 결국 해당 항목이 복제됩니다. – Vitalij