내 레이블이 목록 상자에서 선택한 값을 표시 할 수 있도록 종속성 속성을 사용하려고합니다. 이것은 단지 의존성 프로퍼티의 작동을보다 명확하게 이해하는 것입니다.종속성 속성 ListBox
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WPFToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
xmlns:local="clr-namespace:WpfApplication1" x:Name="MyWindow"
Height="200" Width="300" >
<StackPanel>
<ListBox x:Name="lbColor" Width="248" Height="56" ItemsSource="{Binding TestColor}"/>
<StackPanel>
<Label Content="{Binding Path=Test, ElementName=lbColor}" />
</StackPanel>
</StackPanel>
</Window>
코드 뒤에,
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public ObservableCollection<string> TestColor { get; set; }
public String Test
{
get { return (String)GetValue(TestProperty); }
set { SetValue(TestProperty, value); }
}
// Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TestProperty =
DependencyProperty.Register("Test", typeof(String), typeof(ListBox), new UIPropertyMetadata("Test1"));
public Window1()
{
InitializeComponent();
TestColor = new ObservableCollection<string>();
DataContext = this;
TestColor.Add("Red");
TestColor.Add("Orange");
TestColor.Add("Yellow");
TestColor.Add("Green");
TestColor.Add("Blue");
}
}
}
는 아무도 내가이 종속성 속성을 사용하여 accompalish 방법을 설명해 수 있습니다. 어떻게 든 저는 Dependency Property 개념과 매우 혼동을 느낍니다. 단지 그것을위한 실제 예제를보고 싶었습니다.
종속성 속성을 사용하여 수행하는 작업은 다음을 참조하십시오. http://stackoverflow.com/questions/1723756/why-dependency-properties/1723831#1723831 –
DP를 보여주는 많은 예제가 있음을 이해합니다. 사용 이유와 관련된 문서를 제공하지만 DP가 어떤 단계에서 수행하는지 이해하게하려면 작동하는 것을보고 싶습니다. 어떻게 호출되는지, 어떤 시점에서 값이 설정되고 어떤 값이 설정되고 무엇입니까? – developer